/// <summary> /// Load: Read an object of this class from and XmlNode representation. /// </summary> /// <param name="node">An XmlNode containing a representation of this object.</param> public CargoTask(XmlNode node) { if (node == null) { return; } XmlNode mainNode = node.FirstChild; while (mainNode != null) { try { switch (mainNode.Name.ToLower()) { case "cargo": Amount = new Cargo(mainNode); break; case "mode": Mode = (CargoMode)Enum.Parse(typeof(CargoMode), mainNode.FirstChild.Value); break; } } catch (Exception e) { Report.Error(e.Message); } mainNode = mainNode.NextSibling; } }
//Get flavor-text for the cargoMode. private String getModeStatus(CargoMode m) { String r = "Unknown"; switch (m) { case CargoMode.AcceleratingTowardsDock: r = "Returning to normal space."; break; case CargoMode.DriftingTowardsDock: r = "Drifting towards hyperspace anchor."; break; case CargoMode.HoldingPosition: case CargoMode.Idle: r = "Hyperdrive offline."; break; case CargoMode.Jumping: r = "Jumping!"; break; case CargoMode.JumpRequested: case CargoMode.TeleportingToSpaceDock: case CargoMode.TeleportRequested: r = "Hyperdrive activated!"; break; case CargoMode.ReasonableWaitBeforeJump: r = "Hyperdrive charging for jump."; break; } return r; }
protected override void onPartFixedUpdate() { if (mode == CargoMode.Idle) { teleCount = 0; jumpCount = 0; approachCount = 0; waitCount = 0; } if (mode == CargoMode.ReasonableWaitBeforeJump) { waitCount++; if (waitCount > 300) { mode = CargoMode.JumpRequested; } } if (mode == CargoMode.HoldingPosition) { vessel.SetWorldVelocity(destination.GetVelocityOfDestination(vessel)); } if (mode == CargoMode.AcceleratingTowardsDock) { int safeDistance = 50; if (destination.IsDestinationLanded()) { safeDistance = 50; } if (approachCount == 50) { approachCount++; originalVesselVelocity = vessel.obt_velocity; } else if (approachCount > 2000) { print("Approach is taking too long. Giving up."); vessel.SetWorldVelocity(destination.GetVelocityOfDestination(vessel)); mode = CargoMode.Idle; } else if (destination.GetPreciseDistanceToDestination(vessel).magnitude < safeDistance) { print("Approach successful"); vessel.SetWorldVelocity(destination.GetVelocityOfDestination(vessel)); mode = CargoMode.HoldingPosition; } else if (approachCount < 100) { approachCount++; } else { approachCount++; Vector3 finalVelocity; //print("OriginalVelocity: " + originalVesselVelocity); //print("Current Velocity: " + vessel.obt_velocity); Vector3 reducedVector = new Vector3(); Vector3 scalar = new Vector3(1, 1, 1); scalar = scalar / 1; reducedVector = destination.GetPreciseDistanceToDestination(vessel); //print("Reduced Vector - starts at: " + reducedVector); reducedVector.Scale(scalar); //print("Reduced Vector - scales to: " + reducedVector); finalVelocity = originalVesselVelocity + (reducedVector); //print("FinalVelocity: " + finalVelocity); vessel.SetWorldVelocity(finalVelocity); } } if (mode == CargoMode.DriftingTowardsDock) { } if (mode == CargoMode.TeleportRequested) { mode = CargoMode.TeleportingToSpaceDock; teleCount = 0; approachCount = 0; jumpCount = 0; } if (mode == CargoMode.TeleportingToSpaceDock) { if (teleCount < 1) { print("Zork: Going onto Rails"); Teleport(new Vector3(0, 0, -3000000)); print("Zork: Teleporting: count at " + teleCount); //vessel.transform.position = whereToGoFifth; teleCount++; } else if (teleCount == 1) { Vector3 safeVector = destination.GetSafeDistanceToDestination(vessel); print("Zork: translating to " + safeVector); Teleport(safeVector); RotateToDock(); teleCount++; } else { print("Teleport finished."); print("normalizing speed with target"); MatchSpeedWithDock(); mode = CargoMode.AcceleratingTowardsDock; } } if (mode == CargoMode.JumpRequested) { numberOfJumps++; jumpCount = 0; mode = CargoMode.Jumping; BumpUp(); } if (mode == CargoMode.Jumping) { jumpCount++; if (jumpCount > 15) { mode = CargoMode.TeleportRequested; } } base.onPartFixedUpdate(); }
protected override void onPartAwake() { numberOfJumps = 0; mode = CargoMode.Idle; base.onPartAwake(); }
public void SetCargoMode(CargoMode mode) { print("Jumper acknowledge: mode now at: " + mode); this.mode = mode; }
/// <summary> /// Copy Constructor. /// </summary> /// <param name="other">CargoTask to copy.</param> public CargoTask(CargoTask copy) { Amount = new Cargo(copy.Amount); Mode = copy.Mode; }
/// <summary> /// Default Constructor. /// </summary> public CargoTask() { Amount = new Cargo(); Mode = CargoMode.Unload; }