Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
/* 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();
}
/* 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;
}
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.
Here is with the LCD edits.[pastebin.com]
And an SS.