public void UpdateVessel(ClientObject client, Guid vesselID, byte[] vesselData) { string vesselDataString = Encoding.UTF8.GetString(vesselData); ConfigNode cn = ConfigNodeReader.StringToConfigNode(vesselDataString); string landed = cn.GetValue("landed"); VesselInfo vi = GetVesselInfo(vesselID); if (landed == "True") { double newLat = Double.Parse(cn.GetValue("lat")); double newLong = Double.Parse(cn.GetValue("lon")); double newAlt = Double.Parse(cn.GetValue("alt")); vi.UpdateLanded(newLat, newLong, newAlt, 0); } else { ConfigNode cnOrbit = cn.GetNode("ORBIT"); double[] orbit = new double[7]; orbit[0] = double.Parse(cnOrbit.GetValue("INC")); orbit[1] = double.Parse(cnOrbit.GetValue("ECC")); orbit[2] = double.Parse(cnOrbit.GetValue("SMA")); orbit[3] = double.Parse(cnOrbit.GetValue("LAN")); orbit[4] = double.Parse(cnOrbit.GetValue("LPE")); orbit[5] = double.Parse(cnOrbit.GetValue("MNA")); orbit[6] = double.Parse(cnOrbit.GetValue("EPH")); int referenceBody = Int32.Parse(cnOrbit.GetValue("REF")); Orbit o = new Orbit(orbit, referenceBody); vi.UpdateOrbit(o); } }
private VesselInfo GetVesselInfo(Guid vesselID) { lock (vessels) { if (vessels.ContainsKey(vesselID)) { return(vessels[vesselID]); } VesselInfo vi = new VesselInfo(vesselID); vessels[vesselID] = vi; return(vi); } }
public void PositionVessel(ClientObject client, VesselUpdate update) { if (update.isSurfaceUpdate) { VesselInfo vi = GetVesselInfo(update.vesselID); vi.UpdateLanded(update.position[0], update.position[1], update.position[2], Vector.Length(update.velocity)); } else { VesselInfo vi = GetVesselInfo(update.vesselID); int planetReference = PlanetInfo.GetReference(update.bodyName); if (planetReference != -1) { Orbit o = new Orbit(update.orbit, planetReference); vi.UpdateOrbit(o); } } }
public override void OnUpdate() { if (!inited) { return; } long currentTime = DateTime.UtcNow.Ticks; if (currentTime > lastSendTime + (TimeSpan.TicksPerSecond * UpdateFileSpeed)) { //Console.WriteLine("vessel update!"); lastSendTime = currentTime; lock (vessels) { double currentSubspaceTime = ServerTime.GetTime(); foreach (KeyValuePair <Guid, VesselInfo> kvp in vessels) { VesselInfo vi = kvp.Value; vi.Update(PointTime.GetTime(currentSubspaceTime, 0)); double[] NextposLLH = new double[] { vi.latitude, vi.longitude, vi.altitude }; vi.Update(PointTime.GetTime(currentSubspaceTime, 250)); double[] NextposLLH2 = new double[] { vi.latitude, vi.longitude, vi.altitude }; vi.Update(PointTime.GetTime(currentSubspaceTime, 500)); double[] NextposLLH3 = new double[] { vi.latitude, vi.longitude, vi.altitude }; vi.Update(PointTime.GetTime(currentSubspaceTime, 750)); double[] NextposLLH4 = new double[] { vi.latitude, vi.longitude, vi.altitude }; vi.Update(PointTime.GetTime(currentSubspaceTime, 1000)); double[] NextposLLH5 = new double[] { vi.latitude, vi.longitude, vi.altitude }; vi.Update(currentSubspaceTime); Double TimePercent = PointTime.GetTimePercent(currentSubspaceTime); double[] posLLH = new double[] { vi.latitude, vi.longitude, vi.altitude }; //Console.WriteLine(kvp.Key + " Pos: " + Vector.GetString(posLLH, 2) + " velocity: " + vi.velocity.ToString("F1") + " time: " + currentSubspaceTime.ToString("F1")); string currentvesselDataString = "pid = " + kvp.Key + "\npos = " + Vector.GetString(posLLH, 2) + "\nnextloc = " + Vector.GetString(NextposLLH, 2) + "\nnextloc2 = " + Vector.GetString(NextposLLH2, 2) + "\nnextloc3 = " + Vector.GetString(NextposLLH3, 2) + "\nnextloc4 = " + Vector.GetString(NextposLLH4, 2) + "\nnextloc5 = " + Vector.GetString(NextposLLH5, 2) + "\nvel = " + vi.velocity.ToString("F1") + "\ntime = " + currentSubspaceTime.ToString("F1") + "\ntimep = " + TimePercent.ToString("F1"); byte[] currentvesselData = Encoding.Default.GetBytes(currentvesselDataString); File.WriteAllBytes(Path.Combine(VesselPosFolder, kvp.Key + ".txt"), currentvesselData); } } } }