public void Update() { if (CurrentState == ExtractorState.Deploying && deployStates.All(s => s.normalizedTime >= 1)) { CurrentState = ExtractorState.Deployed; foreach (var state in drillStates) { state.enabled = true; state.normalizedTime = 0; state.speed = 1; } } else if (CurrentState == ExtractorState.Retracting && deployStates.All(s => s.normalizedTime <= 0)) { CurrentState = ExtractorState.Retracted; } foreach (var deployState in deployStates) { var time = Mathf.Clamp01(deployState.normalizedTime); deployState.normalizedTime = time; var speed = HighLogic.LoadedSceneIsEditor ? 1 - 10 * (time - 1) * time : 1; deployState.speed = (CurrentState == ExtractorState.Deploying || CurrentState == ExtractorState.Deployed) ? speed : -speed; } }
public void Deploy() { if (CurrentState != ExtractorState.Retracted) { return; } CurrentState = ExtractorState.Deploying; }
public void Deploy() { if (CurrentState != ExtractorState.Retracted) { return; } CurrentState = ExtractorState.Deploying; foreach (var state in deployStates) { state.speed = 1; } }
public void Retract() { if (CurrentState != ExtractorState.Deployed) { return; } CurrentState = ExtractorState.Retracting; foreach (var state in drillStates) { state.enabled = false; state.normalizedTime = 0; state.speed = 0; } }
public override void OnStart(PartModule.StartState state) { deployStates = Misc.SetUpAnimation(DeployAnimation, this.part); drillStates = Misc.SetUpAnimation(DrillAnimation, this.part); if (CurrentState == ExtractorState.Deploying) { CurrentState = ExtractorState.Retracted; } else if (CurrentState == ExtractorState.Retracting) { CurrentState = ExtractorState.Deployed; } if (CurrentState == ExtractorState.Deployed) { foreach (var deployState in deployStates) { deployState.normalizedTime = 1; } } foreach (var drillState in drillStates) { drillState.enabled = false; drillState.wrapMode = WrapMode.Loop; } }
public override void OnUpdate() { foreach (var deployState in deployStates) { deployState.normalizedTime = Mathf.Clamp01(deployState.normalizedTime); } if (CurrentState == ExtractorState.Deploying && deployStates.All(s => s.normalizedTime == 1)) { CurrentState = ExtractorState.Deployed; foreach (var state in drillStates) { state.enabled = true; state.normalizedTime = 0; state.speed = 1; } } else if (CurrentState == ExtractorState.Retracting && deployStates.All(s => s.normalizedTime == 0)) { CurrentState = ExtractorState.Retracted; } }
public override void OnStart(PartModule.StartState state) { deployStates = Misc.SetUpAnimation(DeployAnimation, this.part); drillStates = Misc.SetUpAnimation(DrillAnimation, this.part); headTransform = this.part.FindModelTransform(HeadTransform); tailTransform = this.part.FindModelTransform(TailTransform); if (CurrentState == ExtractorState.Deploying) { CurrentState = ExtractorState.Retracted; } else if (CurrentState == ExtractorState.Retracting) { CurrentState = ExtractorState.Deployed; } if (CurrentState == ExtractorState.Deployed) { foreach (var deployState in deployStates) { deployState.normalizedTime = 1; } } foreach (var drillState in drillStates) { drillState.enabled = false; drillState.wrapMode = WrapMode.Loop; } if (state == StartState.Editor) { return; } if (FlightGlobals.fetch == null) { return; } emitters = part.Modules.OfType<KethaneParticleEmitter>().ToArray(); foreach (var emitter in emitters) { emitter.Setup(); emitter.EmitterTransform.parent = headTransform; emitter.EmitterTransform.localRotation = Quaternion.identity; } }
public DefaultExtractorAnimator() { CurrentState = ExtractorState.Retracted; }
public void Retract() { CurrentState = ExtractorState.Retracted; }
public void Deploy() { CurrentState = ExtractorState.Deployed; }
private void processBytes() { while (this.currentBytePointer < this.bytes.Count) { switch (this.state) { case ExtractorState.WaitingForStart: // 1. Create a new message this.packet = new BusPacket { From = (BusDevice)bytes[currentBytePointer++] }; // 2. change state to WaitForLen this.state = ExtractorState.WaitingForLength; // 3. Advance current byte pointer break; case ExtractorState.WaitingForLength: var lenValue = bytes[currentBytePointer++]; // 1. If the byte is < 3 (?), change state to LostSync, advance msgstart by 1 and reset bytePointer t osame if (lenValue < 3) { this.state = ExtractorState.LostSync; } else { // 2. set message len to the byte val // 3. advance byte pointer by 1 this.packet.Len = lenValue; this.state = ExtractorState.WaitingForDestination; } break; case ExtractorState.WaitingForDestination: this.packet.Dest = (BusDevice)this.bytes[this.currentBytePointer]; this.currentBytePointer++; this.state = ExtractorState.BuildingPacket; break; case ExtractorState.BuildingPacket: this.packet.Payload.Add(this.bytes[this.currentBytePointer]); // If we have read number of bytes specified by the packet's Len field, // we should expect the XOR if (this.currentBytePointer - this.messageStartPointer == packet.Len) { this.state = ExtractorState.WaitingForXor; } this.currentBytePointer++; break; case ExtractorState.WaitingForXor: // 1. add byte to packet this.packet.Payload.Add(this.bytes[this.currentBytePointer++]); // Perform xor validation if (this.packet.CheckXor()) { // If checksum was ok, add finished packet to output and // start waiting for the next packet this.messageStartPointer = this.currentBytePointer; this.OutputPackets.Enqueue(this.packet); this.state = ExtractorState.WaitingForStart; } else { this.state = ExtractorState.LostSync; } break; case ExtractorState.LostSync: Console.WriteLine($"State: {this.state}"); this.messageStartPointer++; this.currentBytePointer = this.messageStartPointer; this.state = ExtractorState.WaitingForStart; // TODO: // 1. try to parse two messages. // if success, set state to waitingforstart // if failure, advance both by 1 break; } } }
public BmwBusPacketExtractor() { this.bytes = new List <byte>(); this.state = ExtractorState.WaitingForStart; this.OutputPackets = new Queue <BusPacket>(); }
public override void OnUpdate() { foreach (var deployState in deployStates) { deployState.normalizedTime = Mathf.Clamp01(deployState.normalizedTime); } if (CurrentState == ExtractorState.Deploying && deployStates.All(s => s.normalizedTime == 1)) { CurrentState = ExtractorState.Deployed; foreach (var state in drillStates) { state.enabled = true; state.normalizedTime = 0; state.speed = 1; } } else if (CurrentState == ExtractorState.Retracting && deployStates.All(s => s.normalizedTime == 0)) { CurrentState = ExtractorState.Retracted; } if (CurrentState != ExtractorState.Retracted) { RaycastHit hitInfo; var hit = raycastGround(out hitInfo); foreach (var emitter in emitters.Where(e => e.Label != "gas")) { emitter.Emit = hit; } if (hit) { foreach (var emitter in emitters) { emitter.EmitterPosition = headTransform.InverseTransformPoint(hitInfo.point); } } foreach (var emitter in emitters.Where(e => e.Label == "gas")) { if (CurrentState == ExtractorState.Deployed) { emitter.Emit = hit && KethaneController.GetInstance(this.vessel).GetDepositUnder("Kethane") != null; } else { emitter.Emit = false; } } } else { foreach (var emitter in emitters) { emitter.Emit = false; } } }
public override void OnUpdate() { var deployState = deployStates.First(); deployState.normalizedTime = Mathf.Clamp01(deployState.normalizedTime); if (CurrentState == ExtractorState.Deploying && deployState.normalizedTime == 1) { CurrentState = ExtractorState.Deployed; foreach (var state in drillStates) { state.enabled = true; state.normalizedTime = 0; state.speed = 1; } } else if (CurrentState == ExtractorState.Retracting && deployState.normalizedTime == 0) { CurrentState = ExtractorState.Retracted; } var gasEmitter = gasParticles.GetComponent<ParticleEmitter>(); if (CurrentState != ExtractorState.Retracted) { RaycastHit hitInfo; var hit = raycastGround(out hitInfo); sparkParticles.renderer.enabled = sparkParticles.GetComponent<ParticleEmitter>().emit = hit; if (hit) { sparkParticles.GetComponent<ParticleAnimator>().force = Quaternion.FromToRotation(Vector3.forward, Vector3.up) * gasParticles.transform.InverseTransformDirection(FlightGlobals.getGeeForceAtPosition(headTransform.position)); gasParticles.transform.position = hitInfo.point; } if (CurrentState == ExtractorState.Deployed) { gasEmitter.emit = hit && KethaneController.GetInstance(this.vessel).GetDepositUnder() != null; if (gasEmitter.emit) { var gasAnimator = gasParticles.GetComponent<ParticleAnimator>(); var pressure = FlightGlobals.getStaticPressure(headTransform.position); gasAnimator.force = Quaternion.FromToRotation(Vector3.forward, Vector3.up) * gasParticles.transform.InverseTransformDirection(FlightGlobals.getGeeForceAtPosition(headTransform.position)) * (float)pressure * -0.4f; gasEmitter.maxEnergy = 10f + 10f * (float)pressure; gasAnimator.sizeGrow = 0.25f + (float)Math.Exp(-2.7f * pressure); gasAnimator.rndForce = Vector3.one * 8 * (float)pressure; gasAnimator.damping = (float)Math.Exp(-2.3f * pressure); } } else { gasEmitter.emit = false; } } else { sparkParticles.renderer.enabled = sparkParticles.GetComponent<ParticleEmitter>().emit = gasEmitter.emit = false; } }