// Signalled by master about locking. Set flags public void setSlaveLock(uint masterPartId) { printDebug($"setting slave lock by request from {masterPartId}"); isSlave = true; isMaster = false; pairLockPartId = masterPartId; otherLockPart = FlightGlobals.FindPartByID(masterPartId); otherLock = (LockMechanism)otherLockPart.Modules ["LockMechanism"]; lockFSM.state = LockFSM.State.Locking; defaultPostEventAction(); }
public void lockHasp(Part latch) { printDebug($"part={latch.name}; id={latch.flightID}; fsm state={lockFSM.state}"); // If we're not restoring the state after timewarp/load, perform // what it takes to lock the latch if (lockFSM.state == LockFSM.State.Locking) { #if (KSP_151 || KSP_161 || KSP_171) float num = (float)part.RequestResource("ElectricCharge", (double)(new decimal(ecConsumption))); #else float num = part.RequestResource("ElectricCharge", ecConsumption); #endif if (num < ecConsumption) { ScreenMessages.PostScreenMessage("Not enough electric charge to lock the hasp!"); return; } isSlave = false; // If we use genderless locking, tell the other part that we are leading if (isLockablePart(latch) && latch.Modules.Contains("LockMechanism")) { // Both locks could be primed. In that case assign master status // to the part with lesser flightID otherLock = (LockMechanism)latch.Modules ["LockMechanism"]; printDebug($"our fsm state = {lockFSM.state}, other fsm state = {otherLock.lockFSM.state}"); if (otherLock.lockFSM.state != LockFSM.State.Locking || part.flightID < latch.flightID) { printDebug("acquiring master status"); otherLock.setSlaveLock(part.flightID); isMaster = true; } else { printDebug("submitting to slave status"); isSlave = true; } } if (!isSlave) { if (lockSound == null) { lockSound = createAudio(part.gameObject, lockSoundPath); } lockSound.audio.Play(); } } StartCoroutine(finalizeLock(latch)); }
public void processPreLaunch(Vessel v) { printDebug($"new vessel: {v}"); if (v != part.vessel || !startLocked) { return; } // Raycast upright and if there's a lock, create joint Part onLaunchCounterPart = findCounterpartOnLaunch(); if (onLaunchCounterPart == null) { lockFSM.state = LockFSM.State.Ready; return; } // check if other part has id greater than ours and LaunchLocked set // if so, we give up setting a lock and submit to slave status printDebug($"Our id: {part.flightID}, theirs id: {onLaunchCounterPart.flightID}"); // Check for genderless locking if (isLockablePart(onLaunchCounterPart) && onLaunchCounterPart.Modules.Contains("LockMechanism")) { otherLock = (LockMechanism)onLaunchCounterPart.Modules["LockMechanism"]; // Check if we would be a slave lock if (onLaunchCounterPart.flightID > part.flightID) { if (otherLock.startLockedStr.Equals("true", StringComparison.OrdinalIgnoreCase)) { // Lock should be set by other part return; } otherLock.isMaster = true; setSlaveLock(onLaunchCounterPart.flightID); } else { isMaster = true; otherLock.setSlaveLock(part.flightID); } // Setting lock ourselves pairLockPartId = onLaunchCounterPart.flightID; otherLock.lockFSM.state = LockFSM.State.Locked; } lockFSM.state = LockFSM.State.Locked; }
public void offRails(Vessel v) { if (lockFSM.state == LockFSM.State.Locked && lockJoint == null && pairLockPartId != 0) { // If locked and there's no joint, we're restoring from save and joint // must be re-created printDebug("restoring joint; pair=" + pairLockPartId + "; isMaster=" + isMaster); otherLockPart = FlightGlobals.FindPartByID(pairLockPartId); if (otherLockPart != null) { // In case of genderless locking, get other part locking module if ((isMaster || isSlave) && otherLockPart.Modules.Contains("LockMechanism")) { otherLock = (LockMechanism)otherLockPart.Modules ["LockMechanism"]; } jointJustCreated = false; lockHasp(otherLockPart); } } defaultPostEventAction(); msgPosted = false; }