Created
December 13, 2015 16:11
-
-
Save YarekTyshchenko/3cba6a240c20da712356 to your computer and use it in GitHub Desktop.
Replicator Programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main(string argument) | |
{ | |
string state = LoadState(); | |
if (state == BUILD_IN_PROGRESS) { | |
if (KernelBuildFinished()) { | |
WriteText("Build Finished"); | |
SetState(BUILD_FINISHED); | |
} else { | |
WriteText("Build in progress"); | |
} | |
} | |
if (state == BUILD_FINISHED) { | |
RenameEverything(); | |
SetState(WAITING_TO_BE_ALONE); | |
} | |
if (state == WAITING_TO_BE_ALONE) { | |
WriteText(WAITING_TO_BE_ALONE); | |
// Check sensor to see if we are alone | |
} | |
if (state == ALONE) { | |
// Load schematic into projecor and start building | |
} | |
if (state == BUILDING_MAIN_SHIP) { | |
// Report progress | |
} | |
} | |
/* State machine | |
- Kernel build in progress (Connector not disconnected) | |
- Kernel build finished | |
- Waiting to be alone | |
- Alone | |
- Ship build in progress | |
- Ship build done | |
*/ | |
const string STATE_UNKNOWN = "STATE_UNKNOWN"; | |
const string BUILD_IN_PROGRESS = "BUILD_IN_PROGRESS"; | |
const string BUILD_FINISHED = "BUILD_FINISHED"; | |
const string WAITING_TO_BE_ALONE = "WAITING_TO_BE_ALONE"; | |
const string ALONE = "ALONE"; | |
const string BUILDING_MAIN_SHIP = "BUILDING_MAIN_SHIP"; | |
const string SLEEP = "SLEEP"; | |
string LoadState() { | |
string s = Storage; | |
if(s.Length = 0) { | |
return STATE_UNKNOWN; | |
} | |
return s; | |
} | |
void SetState(string state) { | |
Storage = state; | |
} | |
void RenameEverything() { | |
// Rename everything | |
connector.SetCustomName("Kernel Connector"); | |
} | |
IMyShipConnector connector; | |
bool KernelBuildFinished() { | |
// Scan all ship for connectors. After build step there should only be one | |
List<IMyTerminalBlock> connectors = new List<IMyTerminalBlock>(); | |
GridTerminalSystem.GetBlocksOfType<IMyShipConnector>(connectors); | |
if (connectors.Count != 1) { | |
return false; | |
} | |
connector = (IMyShipConnector)connectors[0]; | |
return ! connector.IsConnected; | |
} | |
void WriteText(string text) { | |
IMyTextPanel lcd = GridTerminalSystem.GetBlockWithName("Build Panel") as IMyTextPanel; | |
lcd.WritePublicText(text); | |
Echo(text); | |
lcd.ShowTextureOnScreen(); | |
lcd.ShowPublicTextOnScreen(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment