Space Engineers

Space Engineers

Clang Drive Manager
Lynnuxx 24 Aug, 2024 @ 8:36am
Improvement for "docking with other grids"
Very nice script, works pretty well. I use it for a planetary orbiter where it replaces the originally planned grav drive / hydro thruster combo.

Problem 1: Script loses the clang drives on docking
When docking a vehicle via connector I noticed the the script was losing the clang drives.
It seems this happens because the first ship controller found is on this vehicle.
The small block vehicle also becomes the master grid but I don't know if this influences the order in which the ship controllers are searched for and subsequently are found.
The script then searches for clang drives which are on the same grid as the found ship controller. In my case this is the vehicle and hence no clang drives are found anymore.

In case you just want to find clang drives on the same grid as the programmable block and ship controller you just have to add the check of the cubegrid as shown below:
void FindController()
{
Controllers = new List<IMyShipController>();
GridTerminalSystem.GetBlocksOfType<IMyShipController>(Controllers);

for(int i=Controllers.Count()-1; i>-1; i--) if(Controllers[i].CanControlShip == false) Controllers.RemoveAt(i); //remove bathrooms, couches etc.
Controllers.RemoveAll(x => (x.CustomName.Contains(ignoretag)) && (x.CubeGrid != Me.CubeGrid));

Problem 2: I don't want to tag blocks (connectors, merge blocks, rotors, ...) of all creations possibly connecting to my ship
In this case the solution via ignoretag doesn't help much since you have to possibly tag (=add "[ignore]" to the name) dozens of blocks in other objects.
Better is to use a positive logic, so I've added includetag and set it to "(clang drive)" since you already use this tag in some of your blueprints.
This will only find clang drives with its blocks tagged this way. If you want to find all (tagged and untagged) blocks again, just set includetag = "".

This can be achieved by adding a filter to GetBlocksOfType(list, bool filter), e.g. by adding a method like IsBlockIncluded here:
bool IsBlockIncluded(IMyTerminalBlock bl)
{
return bl.CustomName.Contains(includetag);
}

void Init()
{
//pile up all necessary blocks, they could all be part of a drive, or not
MergeBlocks = new List<IMyShipMergeBlock>();
GridTerminalSystem.GetBlocksOfType<IMyShipMergeBlock>(MergeBlocks, IsBlockIncluded);

...or by adding a lambda, looks like you prefer this:
void Init()
{
//pile up all necessary blocks, they could all be part of a drive, or not
MergeBlocks = new List<IMyShipMergeBlock>();
GridTerminalSystem.GetBlocksOfType<IMyShipMergeBlock>(MergeBlocks, x => x.CustomName.Contains(includetag));
Last edited by Lynnuxx; 24 Aug, 2024 @ 8:49am