private void ConnectToReactor() { // first try to look in part _attached_reactor = this.part.FindModuleImplementing <IChargedParticleSource>(); // try to find nearest if (_attached_reactor == null) { _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1); } if (_attached_reactor != null) { _attached_reactor.ConnectWithEngine(this); } }
private IChargedParticleSource BreadthFirstSearchForChargedParticleSource(int stackdepth, int parentdepth) { for (int currentDepth = 0; currentDepth <= stackdepth; currentDepth++) { IChargedParticleSource particleSource = FindChargedParticleSource(part, currentDepth, parentdepth); if (particleSource != null) { particleSource.ConnectWithEngine(this); _attached_reactor_distance = currentDepth; return(particleSource); } } return(null); }