Space Engineers

Space Engineers

[CAT] Cat-Oh-Lith Preset ~ strong & weak Signals
Loues.S.Cat  [developer] 12 Sep, 2017 @ 3:28am
Cat-Oh-Lith Script
:xerxes::datadisk::shodan:

/*
* Cats makes the best programmers!
* Cat-Oh-Lith management script
*/

string GS_Prefix = "[COL]";

string GS_ProjPri = "none";
string GS_ProjSec = "none";
List<IMyTerminalBlock> GL_ProjBlocks;

// This is now reset every tick
IMyCubeGrid GO_SubGridRef = null; // grid refferance for projector grid

/* GEN VARIABLES */
int GI_RotorPauseCount = 0;
int GI_RotorAngleInd = 0;

/* TOOL VARIABLES */
bool GB_ToolState = false; // tool on/off state

/* ROTOR VARIABLES */
int GI_RotarRot = 0;

/* PROJECTOR VARIABLES */
int GI_Pow = 0; // current power
string[] GA_PowStr = { "Weak", "Strong" }; // descriptor
bool GB_Pro_Alt = false; // used in alternating mode

/* LIGHT VARIABLES */
Color[] GA_SigCol = {
new Color( 0, 255, 0 ),
new Color( 255, 255, 0 )
}; // [0] green (weak), [1] Yellow (strong)

/* LOGGING VARIABLES */
List<string> GL_ActLog;
List<string> GL_SC_Report;

/* LCD VARIABLES */
List<Color> GO_LCD_TextCol = new List<Color>() {
new Color(255,0,0),
new Color(0,255,0),
new Color(255,255,0),
new Color(255,0,255)
};

/* SPECIAL CONTENT VARIABLES */
//string GS_SC_Button = "Special Content";
List<IMyTerminalBlock> GL_SC_Log = new List<IMyTerminalBlock>();


/* Sound and Sense */
bool GB_GensOn = false;

bool GB_Users = false;

string[] GA_Sounds = new string[] {
"Drone - Huge",
"Drone - Small"
};

bool GB_Setup = false;

string GS_DefData =
" >>>___INSTRUCTIONS___<<<"+Environment.NewLine+
" #1 *REDACTED*"+Environment.NewLine+Environment.NewLine+
" #2 Locate the Cat-Oh-Lith (It's This Thing). "+Environment.NewLine+Environment.NewLine+
" #3 Locate Access Aperture on Cat-Oh-Lith."+Environment.NewLine+Environment.NewLine+
" #2 Inset a Suitable limb into Aperture."+Environment.NewLine+Environment.NewLine+
" #iiv Click the Ominous Glowing Button."+Environment.NewLine+Environment.NewLine+
" #G $Parse_Err: 'DATA_EXPUNGED'"+Environment.NewLine+Environment.NewLine+
" #7 PROFFIT!!!"+Environment.NewLine+Environment.NewLine;

/* LEGACY BITS. DON'T USE */

/*
* This works, but keen are going to kill (and maybe replace) it eventualy.
* in single projector mode this is useful, however it requires true path information so requires manual setup
* Basicly don't bother using this
*/
string GS_Path_Start = "INSERT PATH HERE"; // path prefix
string[] GA_Path_Core = { "SC_Weak_Signal", "SC_Strong_Signal" }; // blueprint(folder) name - first is weak - second is strong
string GS_Path_End = "/bp.sbc"; // file name. Same for all local blueprints
/*
* As above and...
* Sigh. Can't use workshop items because they are the wrong type.
*/
/*
string GS_Path_Start = "BLARK!!!";
string[] GA_Path_Core = { "1131617065", "1131617431" };
string GS_Path_End = ".sbb";
*/

/* END OF LEGACY BITS */


/*
* Main again...
* What is this a Steven King novel?
* Also found in Maine:
* The redemptive drunkard
* Ridiculously excessive bullies that are clearly sadistic psychopaths that result to murder with little prompting
* Endless flashbacks
* Recurring heavy handed suggestions that religion is evil
* An unexplained evil force without justification for its existence.
* The disabled child with magic/psychic powers.
*/
public void Main( string arg ) {
Echo( new StringBuilder( "ET: " ).Append( Runtime.TimeSinceLastRun ).Append( Environment.NewLine ).Append( "CAT Cat-Oh-Lith" ).ToString() );

if( !GB_Setup ) {
SetReactors( true );
DoSetup();
SetupSensor();
}

GL_ActLog = new List<string>(); // report output AL cleared
GL_ActLog.Add( "___ACTION LOG___" ); // report AL output
if( !UpdateGridRef() ) { // reset refgrid
GL_ActLog.Add( "> Ref Gen Fail" ); // report AL output
} else { // if grid refs are already set
GL_ActLog.Add( "> Ref Gen Pass" ); // report AL output
DefaultOpperation(); // perform standard run
}

UpdateDisplays( ); // update display
}




/* SINGLE CALL FUNCTION
* Primarily setupfunctions that will likely only be called once in the running of the script.
*/

/*
* Setup Process
*/
public void DoSetup() {
if( UpdateGridRef() ) { // check if ref grids are not yet set...
RebuildStructure(); // if ref grids set rewrite grid names
GB_Setup = true;
} else {
Echo( "Initalisation Failed" );
GB_Setup = false;
}
}

/*
* Called only once to rebuild name convention
* This way lies maddness
*/
public void RebuildStructure() {
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyTerminalBlock>( blocks, CheckEitherGrid ); // get all terminal blocks on primary or secondary grid
//int proj = 0; // log the number of projectors found. There should be only 2 (or 1)
var projs = new List<IMyTerminalBlock>();

Me.CubeGrid.CustomName = "Cat-Oh-Lith";

for( int i = 0; i < blocks.Count; i++ ) {
if( blocks[i].BlockDefinition.ToString().Substring( Math.Max( 0, blocks[i].BlockDefinition.ToString().Length - 9 ) ) == "Projector" ) { // check if the current block is a projector
projs.Add( blocks[i] );
} else if( blocks[i].BlockDefinition.ToString().Substring( Math.Max( 0, blocks[i].BlockDefinition.ToString().Length - 17 ) ) == "ProgrammableBlock" ) {
if( blocks[i] == Me ) {
blocks[i].CustomName = GS_Prefix +" "+ blocks[i].DefinitionDisplayNameText +" [Pri]";
} else {
blocks[i].CustomName = GS_Prefix +" "+ blocks[i].DefinitionDisplayNameText;// +" [Sec]";
}
} else { // if it isnt a projector
blocks[i].CustomName = GS_Prefix +" "+ blocks[i].DefinitionDisplayNameText;
}
}

ProcessProjectors( projs );

if( projs.Count > 2 ) {
Echo ( "Too many projectors found" );
}
}

/*
* Process Projectors
* There should be 2 but it can cope with more as long as the 2 are propperly tagged
* if it doesn't find the 2 tagged projectors it will tag new ones.
* This may go horrible wrong, but it does a grid check so... what the hell would more than 2 projectors be on the rotor subgrid for anyway?
*/
public void ProcessProjectors( List<IMyTerminalBlock> projs ) {
Echo( "Processing Projectors" );
if( projs.Count >= 2 ) {
bool st = false;
bool we = false;
for( int i = 0; i < projs.Count; i++ ) { // find and setup the strong and weak projector
if( projs[i].CustomData == "strong" ) {
st = true;
GS_ProjPri = GS_Prefix +" "+ projs[i].DefinitionDisplayNameText +" [Strong]";
projs[i].CustomName = GS_ProjPri;
} else if( projs[i].CustomData == "weak" ) {
we = true;
GS_ProjSec = GS_Prefix +" "+ projs[i].DefinitionDisplayNameText +" [Weak]";
projs[i].CustomName = GS_ProjSec;
} else {
projs[i].CustomName = GS_Prefix +" "+ projs[i].DefinitionDisplayNameText +" [Blank]";
}
}

if( !st || !we ) { // if strong or weak projector aren't found, appropriate them from unset
for( int i = 0; i < projs.Count; i++ ) {
if( projs[i].CustomData != "strong" && projs[i].CustomData != "weak" ) {
if( !we ) {
we = true;
projs[i].CustomName = GS_Prefix +" "+ projs[i].DefinitionDisplayNameText +" [Weak]";
projs[i].CustomData = "weak";
} else if( !st ) {
st = true;
projs[i].CustomName = GS_Prefix +" "+ projs[i].DefinitionDisplayNameText +" [Strong]";
projs[i].CustomData = "strong";
}

}
}
}
} else if ( projs.Count == 1 ) { // only one projector? ~ only occurs in solo mode which only I should be using so...
GS_ProjSec = "None";
GS_ProjPri = GS_Prefix +" "+ projs[0].DefinitionDisplayNameText +" [Solo]";
projs[0].CustomName = GS_ProjPri;
} else {
GS_ProjPri = "None";
GS_ProjSec = "None";
Echo( "No Projectors Found" );
}
}

/* END OF SINGLE CALL FUNCTIONS */
< >
Showing 1-5 of 5 comments
Loues.S.Cat  [developer] 12 Sep, 2017 @ 3:29am 
:xerxes::datadisk::shodan:

/* Flow Control Functions
* Called Once or so each time the script triggers
*/

/*
* standard action method performed every tick during standard opperation
*/
public void DefaultOpperation() {
CheckSensor();
CheckSound();
CheckPower();

if( (GB_Users || GB_ToolState) && UpdateRotor() ) {
UpdateProjector(); // update the projector
UpdateLights(); // update light values
CheckSpecialContent(); // update button values
}
}

/*
* Find all Grid Refferances
* There should be one rotor on the primary grid...
* If the first rotor found isnt the desired one this goes horribly wrong
* Don't attach extra rotors to the Primary Grid
*/
public bool UpdateGridRef() {
//GO_GridRef = Me.CubeGrid; // get base grid based on programable block CubeGrid
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyMotorStator> ( blocks, CheckGridPri ); // using base grid ref find rotor heads

if( blocks.Count == 1 ) { // there can be only one
GO_SubGridRef = (blocks[0] as IMyMechanicalConnectionBlock).TopGrid; // fetch rotor top attached grid
} else {
GO_SubGridRef = null;
}

//if( GO_GridRef != null && GO_SubGridRef != null && GO_GridRef != GO_SubGridRef ) { // check both found
if( GO_SubGridRef != null ) {
return true; // we found all grids
}
return false; // return false if either grid not found
}

/*
* Update the rotor
*/
public bool UpdateRotor() {
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyMotorBase>( blocks, CheckGridPri );
if( blocks.Count == 1 ) { // only 1 rotor should be found
GL_ActLog.Add( "> Rotor Updated" ); // report AL output
GI_RotarRot = RadsToDeg( ((IMyMotorStator)blocks[0]).Angle ); // angle or rotor

if( GI_RotarRot % 90 == 0 ) { // if it is a 90 degree incrament
if( GB_ToolState == false ) { // if tools are off
EnableTools( !GB_ToolState ); // turn tools on
} else {
GI_RotorPauseCount = (GI_RotorPauseCount+1)%6; // wait steps
if( GI_RotorPauseCount == 0 ) {
EnableTools( !GB_ToolState ); // disable tools
GI_RotorAngleInd = (GI_RotorAngleInd+1)%4; // incrament desired position of rotor
SetRotor( blocks[0], 90*GI_RotorAngleInd );
return true;
}
}
}
return false;
}
// too many or not enough rotors found
GL_ActLog.Add( "> Rotor Not Found" ); // report AL output
return false;
}

/*
* Set Rotor Limits
* compensate for offset bug
*/
public void SetRotor( IMyTerminalBlock block, int ang ) {
((IMyMotorBase)block).SetValueFloat( "LowerLimit", ang ); // reset rotor desired position
((IMyMotorBase)block).SetValueFloat( "UpperLimit", ang ); // as above
/*
* For some reason rotors keep forgetting this displacement...
* So check displacement and if it isn't right remind the rotor to stop being a ♥♥♥♥.
* You have one job Rotors! Stop screwing it up!
*/
if( ((IMyMotorBase)block).GetValue<Single>( "Displacement" ) != 0 ) {
((IMyMotorBase)block).SetValue<Single>( "Displacement", (Single)0 );
}
}

/*
* turn on and off the welder and grinder
*/
public void EnableTools( bool on ) {
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyShipToolBase>( blocks, CheckGridPri );
GB_ToolState = on;
if( blocks.Count == 2 ) { // there should only be two tools. one welder and one grinder
GL_ActLog.Add( "> Tools Updated" ); // report AL output
for( int i = 0; i < blocks.Count; i++ ) { // enable/disable tools
blocks[i].SetValue<bool>( "OnOff", on );
}
} else {
GL_ActLog.Add( "> Tool(s) Not Found" ); // report AL output
}
}

/*
* Update activre projections
* Determins which button is being built
* and the position the projections are being shown in
*/
public void UpdateProjector() {
var blocks = FetchProjectors();
GL_ProjBlocks = blocks;

if( blocks.Count == 2 ) { // check that there are 2 rotors.
GL_ActLog.Add( "> Projectors Updated" ); // report AL output
GB_Pro_Alt = !GB_Pro_Alt; // flip active projector global ref

GI_Pow = (GI_Pow+1) % GA_PowStr.Length; // only used for lights in alt mode

for( int i = 0; i < blocks.Count; i++ ) {
bool on = true; // set on state
if( i == 0 ) { // determin which projector should be on
on = !GB_Pro_Alt;
} else {
on = GB_Pro_Alt;
}

blocks[i].SetValue<bool>( "OnOff", on );
if( on ) {
if( i == 0 ) {
GL_ActLog.Add( "> Set Power: Preset" ); // report AL output
} else {
GL_ActLog.Add( "> Set Alt: Preset" ); // report AL output
}
blocks[i].SetValue<bool>( "KeepProjection", false ); // just in case - true can interfear with button use
blocks[i].SetValue<bool>( "ShowOnlyBuildable", true ); // just in case - hide the unweldable bits
blocks[i].SetValue<Single>( "RotX", (Single)((GI_RotorAngleInd)-1) ); // set rotation of projection
}
}
} else { // too many or too few projectors found
if( blocks.Count == 1 ) {
UpdateSoloProjector( blocks[0] );
} else {
GL_ActLog.Add( "> Projector(s) Not Found" ); // report AL output
}
}
}

/*
* Legacy Code.
* You shouldn't be using this
*/
public void UpdateSoloProjector( IMyTerminalBlock block ) {
GL_ActLog.Add( "> Projector Updated" );

GI_Pow = (GI_Pow+1) % GA_Path_Core.Length;

string path = new StringBuilder( GS_Path_Start ).Append( GA_Path_Core[GI_Pow] ).Append( GS_Path_End ).ToString();

if( ((IMyProjector)block).LoadBlueprint( path ) ) {
GL_ActLog.Add( "> Set Power: "+ GA_PowStr[GI_Pow] );
block.SetValue<bool>( "OnOff", true );
block.SetValue<bool>( "KeepProjection", true );
block.SetValue<bool>( "ShowOnlyBuildable", true );
block.SetValue<Single>( "RotX", (Single)((GI_RotorAngleInd)-1) );
} else {
Echo( "Load Blueprint Failed" );
GL_ActLog.Add( "> Set Power Failed" );
}
}

/*
* Get Primary and secondary projector
*/
public List<IMyTerminalBlock>FetchProjectors() {
var blocks = new List<IMyTerminalBlock>();
var seek = new List<IMyTerminalBlock>();
GridTerminalSystem.SearchBlocksOfName( GS_ProjPri, seek, CheckGridSec );
if( seek.Count >= 1 ) {
blocks.Add( seek[0] );
}
GridTerminalSystem.SearchBlocksOfName( GS_ProjSec, blocks, CheckGridSec );
if( seek.Count >= 1 ) {
blocks.Add( seek[0] );
}
GL_ProjBlocks = blocks;
return blocks;
}

/*
* Set Light colour to show which projector is active
* if all goes well this should line up with which is weak and which is strong
*/
public void UpdateLights() {
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyLightingBlock>( blocks, CheckGridPri );
for( int i = 0; i < blocks.Count; i++ ) {
((IMyLightingBlock)blocks[i]).Color = GA_SigCol[(GI_Pow+1)%2];
((IMyLightingBlock)blocks[i]).Falloff = 2;
((IMyLightingBlock)blocks[i]).Intensity = 5;
((IMyLightingBlock)blocks[i]).Radius = 4;
}
}

/*
* Find and update Special Content
*/
public void CheckSpecialContent() {
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyButtonPanel>( blocks, CheckGridSec );

GL_ActLog.Add( "> Verifying Buttons" ); // report AL output
GL_SC_Report = new List<string>(); // report output SC cleared
GL_SC_Report.Add( "__SC_Log__" ); // report SC output
for( int i = 0; i < blocks.Count; i++ ) { // search through all buttons
if( !GL_SC_Log.Exists( block => block == blocks[i] ) ) { // if the current button isnt in the existing log update the buttons settings
blocks[i].SetValue<bool>( "AnyoneCanUse", true ); // set anyone can use this button
((IMyButtonPanel)blocks[i]).SetCustomButtonName( 0, "Praise Be To CAT!" ); // set button value
GL_SC_Report.Add( "> New Button Added" ); // report SC output
} else {
GL_SC_Report.Add( "> Old Button Found" ); // report SC output
}
}
GL_SC_Log = blocks; // clear & update log of set buttons
GL_SC_Report.Add( "> Button Log Updated" ); // report SC output
}



/* DISPLAY FUNCTIONS
* For Feedback and data display
*/

/*
* Final Report function.
* Sets all LCD values
*/
public void UpdateDisplays( ) {
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyTextPanel>( blocks, CheckGridPri );
if( blocks.Count != 0 ) {
GL_ActLog.Add( "> Displays Found "+ blocks.Count.ToString() ); // report AL output
for( int i = 0; i < blocks.Count; i++) {
//Echo( "Display Update: "+ i.ToString() );
if( i == 0 ) { // set value of displays 0-3
SetLCD( blocks[i], ReportGlobal(), i );
} else if( i == 1 ) {
SetLCD( blocks[i], String.Join( Environment.NewLine, GL_ActLog.ToArray() ), i );
} else if( i == 2 ) {
SetLCD( blocks[i], ReportProjector(), i );
} else if( i == 3 ) {
var scRep = "__No Data__";
if( GL_SC_Report != null ) {
scRep = String.Join( Environment.NewLine, GL_SC_Report.ToArray() );
}
SetLCD( blocks[i], scRep, i );
((IMyTextPanel)blocks[i]).WritePublicText( scRep, false );
} else { // too many displays found?
SetLCD( blocks[i], GS_DefData, -1, 0.55 );
}
}

} else {
GL_ActLog.Add( "> Display(s) Not Found" ); // report AL output

var rep = String.Join( Environment.NewLine, GL_ActLog.ToArray() );
if( blocks.Count == 1 ) {

((IMyTextPanel)blocks[0]).WritePublicText( rep, false );
} else {
Echo( rep );
}
}

}

/*
* Set LCD display data
*/
public bool SetLCD( IMyTerminalBlock block, string strIn, int col, double size = 1.2 ) {
Color colVal = new Color( 255,150,255 );
if( col >= 0 && col < GO_LCD_TextCol.Count ) {
colVal = GO_LCD_TextCol[col];
}
if( block != null && strIn != null ) {
((IMyTextPanel)block).WritePublicText( strIn, false );
block.SetValue<Int64>( "Font", 1147350002 ); // set to... mono? I cant remember
block.SetValue<Color>( "FontColor", colVal ); // set preset font colour
block.SetValue<Single>( "FontSize", (Single)size ); // set font size
block.SetValue<Color>( "BackgroundColor", new Color( 0, 0, 0 ) ); // set BG colour
block.SetValue<bool>( "ShowTextOnScreen", true ); // make sure text is showing
//Echo( blocks[i].GetValue<Int64>( "Font" ).ToString() );
return true;
}
return false;
}

/*
* Build a report of the projectors status
*/
public string ReportProjector() {
GL_ActLog.Add( "__Projector Report__" ); // report AL output
StringBuilder sb = new StringBuilder();

if( GO_SubGridRef != null ) {
List<IMyTerminalBlock> blocks;

if( GL_ProjBlocks != null ) {
blocks = GL_ProjBlocks;
} else {
blocks = FetchProjectors();
}

for( int i = 0; i < blocks.Count; i++ ) {
if( i == 0 ) {
sb.Append( Environment.NewLine ).Append( "__Projector_Report__" ).Append( Environment.NewLine );
} else {
sb.Append( Environment.NewLine ).Append( "__Alt_Report__" ).Append( Environment.NewLine );
}
sb.Append( "> Active: " ).Append( blocks[i].GetValue<bool>( "OnOff" ) ).Append( Environment.NewLine );
sb.Append( "> Sustain: " ).Append( BoolToString( blocks[i].GetValue<bool>( "KeepProjection" ) ) ).Append( Environment.NewLine );
sb.Append( "> Open Only: " ).Append( blocks[i].GetValue<bool>( "ShowOnlyBuildable" ) ).Append( Environment.NewLine );
sb.Append( "> Pro.Rot: " ).Append( blocks[i].GetValue<Single>( "RotX" ).ToString() ).Append( Environment.NewLine );
}
if( blocks.Count == 0 ) {
sb.Append( "> Err: Projector(s) Not Found" );
}
} else {
sb.Append( "> Err: Grid Ref Not Set" );
}
return sb.ToString();
}

/*
*
*/
public string ReportGlobal() {
StringBuilder sb = new StringBuilder(); // report string
sb.Append( "__" ).Append( "Cat-Oh-Lith Status" ).Append( "__" ).Append( Environment.NewLine );
sb.Append( "> RT: " ).Append( Runtime.TimeSinceLastRun.TotalMilliseconds.ToString( ) ).Append( "ms" ).Append( Environment.NewLine );
sb.Append( "> Tool State: " ).Append( BoolToString( GB_ToolState ) ).Append( Environment.NewLine );
sb.Append( "> Rotation: " ).Append( GI_RotarRot.ToString() ).Append( Environment.NewLine );
sb.Append( "> Signal: " ).Append( GA_PowStr[(GI_Pow+1)%2] ).Append( Environment.NewLine );
sb.Append( "> Ticker: " ).Append( GI_RotorPauseCount.ToString() ).Append( Environment.NewLine );
sb.Append( "> Active: " ).Append( BoolToString( GB_Users ) ).Append( Environment.NewLine );
return sb.ToString();
}
Last edited by Loues.S.Cat; 12 Sep, 2017 @ 3:29am
Loues.S.Cat  [developer] 12 Sep, 2017 @ 3:30am 
:xerxes::datadisk::shodan:




/* UNSORTED FUNCTIONS
* Merged in from secondary script
*/

public void CheckPower() {
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>( blocks, CheckGridPri );
Echo( "__Power_Report__" );
float pow_sto = 0;
float pow_max = 0;
for( int i = 0; i < blocks.Count; i++ ) {
IMyBatteryBlock bat = (IMyBatteryBlock)blocks[i];
pow_sto += bat.CurrentStoredPower;
pow_max += bat.MaxStoredPower;
//Echo( bat.CurrentStoredPower.ToString() +"/"+ bat.MaxStoredPower.ToString() );
}

double per = 0;
if( pow_max != 0 ) {
per = Math.Round( (pow_sto / pow_max) * 100 );
}

if( per > 20 && GB_GensOn ) {
SetReactors( false );
} else if( per < 10 && !GB_GensOn ) {
SetReactors( true );
}
Echo( "Battery: "+ per.ToString() );
if( GB_GensOn ) {
Echo( "Reactors: On" );
} else {
Echo( "Reactors: Off" );
}
}

public void SetReactors( bool on ) {
GB_GensOn = on;
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyReactor>( blocks, CheckGridPri );
for( int i = 0; i < blocks.Count; i++ ) {
blocks[i].SetValue<bool>( "OnOff", on );
}
}

public void CheckSound() {
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMySoundBlock>( blocks, CheckGridPri );
Echo( "__Sound_Report__" );
for( int i = 0; i < blocks.Count; i++ ) {
string val = System.Text.RegularExpressions.Regex.Replace( blocks[i].DetailedInfo, "[^0-9]", "" ); // get current rotation of rotor
if( val.Length == 0 ) {
if( i < GA_Sounds.Length ) {
SetSound( blocks[i], GA_Sounds[i] );
Echo( ((IMySoundBlock)blocks[i]).SelectedSound +": [Restarting]" );
} else {
Echo( ((IMySoundBlock)blocks[i]).SelectedSound +": [NIU]" );
}
} else {
Echo( ((IMySoundBlock)blocks[i]).SelectedSound +": ["+ val +"]" );
}
}
}

/*
*
*/
public void SetSound( IMyTerminalBlock block, string sound ) {
if( block != null && sound != null ) {
(block as IMySoundBlock).SelectedSound = sound;
block.SetValue<bool>( "OnOff", true );
block.SetValue<Single>( "RangeSlider", 50 );
block.SetValue<Single>( "VolumeSlider", 100 );
block.SetValue<Single>( "LoopableSlider", 1800 );
(block as IMySoundBlock).Play();
}
}

/*
* Find and evaluate the sensor(s)
*/
public void CheckSensor() {
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMySensorBlock>( blocks, CheckGridPri );
Echo( "__Scan_Report__" );
if( blocks.Count >= 1 ) {
List<MyDetectedEntityInfo> LifeScan = new List<MyDetectedEntityInfo>();
((IMySensorBlock)blocks[0]).DetectedEntities( LifeScan );
if( LifeScan.Count >= 1 ) {
GB_Users = true;
} else {
GB_Users = false;
}
for( int i = 0; i < LifeScan.Count; i++ ){
Echo( "#"+ (i+1).ToString() +"/"+ LifeScan.Count.ToString() +" "+ LifeScan[i].Name );
}
} else {
GB_Users = true;
}
}

/*
*
*/
public void SetupSensor() {
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMySensorBlock>( blocks, CheckGridPri );
if( blocks.Count >= 1 ) {
SetSensor( blocks[0] );
}
}

/*
* set up the sensor
*/
public void SetSensor( IMyTerminalBlock block ) {
if( block != null ) {
block.SetValue<Single>( "Left", 5 );
block.SetValue<Single>( "Right", 5 );
block.SetValue<Single>( "Back", 5 );
block.SetValue<Single>( "Front", 10 );
block.SetValue<Single>( "Top", 4 );
block.SetValue<Single>( "Bottom", 8 );

block.SetValue<bool>( "Audible Proximity Alert", false );
block.SetValue<bool>( "Detect Players", true );
block.SetValue<bool>( "Detect Floating Objects", false );
block.SetValue<bool>( "Detect Small Ships", false );
block.SetValue<bool>( "Detect Large Ships", false );
block.SetValue<bool>( "Detect Stations", false );
block.SetValue<bool>( "Detect Subgrids", false );
block.SetValue<bool>( "Detect Asteroids", false );

block.SetValue<bool>( "Detect Owner", true );
block.SetValue<bool>( "Detect Friendly", true );
block.SetValue<bool>( "Detect Neutral", true );
block.SetValue<bool>( "Detect Enemy", true );
}
}




/* UTILITY FUNCTIONS
* Called whenever and whereever.
* These exist to make life easier and can be used in numerous locations
*/

/*
*
*/
public int RadsToDeg( double rads ) {
return (int)Math.Round( rads * ( 180 / Math.PI ) );
}

/*
* I can't think of a beter way to do this
*/
public string BoolToString( bool on ) {
if( on ) {
return "On";
}
return "Off";
}

/*
* for grid refferane of blocks
*/
public bool CheckGridPri( IMyTerminalBlock block ) { // seperated out to make it clear what it is doing
if( block.CubeGrid == Me.CubeGrid ) {
return true;
}
return false;
}

/*
* for grid refferane of blocks
*/
public bool CheckGridSec( IMyTerminalBlock block ) { // seperated out to make it clear what it is doing
if( GO_SubGridRef == null || block.CubeGrid == GO_SubGridRef ) {
return true;
}
return false;
}

/*
* for grid refferane of blocks
*/
public bool CheckEitherGrid( IMyTerminalBlock block ) { // seperated out to make it clear what it is doing
if( GO_SubGridRef == null || block.CubeGrid == Me.CubeGrid || block.CubeGrid == GO_SubGridRef ) {
return true;
}
return false;
}
Loues.S.Cat  [developer] 27 Feb, 2018 @ 4:28pm 
Huh.
This script is now wrong... and has been for a while.
It is a pain in the ass to post scripts on the forums.
They typicly get broken anyway when copy and pasted here.
lucifier 28 Aug, 2020 @ 1:24pm 
any updates on this mod/script?
Trencher 16 Mar, 2023 @ 3:12pm 
Still works great! I tweaked the LCD screens, centering headings and making the instructions screen more readable. Obviously take or leave it. Side note, maybe expose the battery low/high limits as variables at top, and move sound block on/off up there too, for scripting noobs.

Here is with the LCD edits.[pastebin.com]

And an SS.
< >
Showing 1-5 of 5 comments
Per page: 1530 50