public GPLocation getLocation(double jdate) { if (jdate < julianStart) { return(temp); } if (jdate > julianEnd) { return(temp); } double lonA, lonB; double latA, latB; lonA = LocationA.GetLongitudeEastPositive(); lonB = LocationB.GetLongitudeEastPositive(); latA = LocationA.GetLatitudeNorthPositive(); latB = LocationB.GetLatitudeNorthPositive(); temp.setTimeZone(TimezoneStart ? LocationA.getTimeZone() : LocationB.getTimeZone()); temp.setLongitudeEastPositive(lonA + (lonB - lonA) * (jdate - julianStart) / (julianEnd - julianStart)); temp.setLatitudeNorthPositive(latA + (latB - latA) * (jdate - julianStart) / (julianEnd - julianStart)); //Debugger.Log(0, "", String.Format("== longitude/latitude {0} {1}\n", temp.getLongitudeString(), temp.getLatitudeString())); temp.SetAltitude(0); return(temp); }
public void writeToXmlNode(XmlElement elem, XmlDocument doc) { XmlElement e1; e1 = doc.CreateElement("LocationA"); elem.AppendChild(e1); LocationA.writeToXmlNode(e1, doc); e1 = doc.CreateElement("LocationB"); elem.AppendChild(e1); LocationB.writeToXmlNode(e1, doc); e1 = doc.CreateElement("Time"); elem.AppendChild(e1); e1.SetAttribute("TzStart", TimezoneStart.ToString()); e1.SetAttribute("JuStart", julianStart.ToString()); e1.SetAttribute("JuEnd", julianEnd.ToString()); }
public GPLocation getTravellingLocation(double ratio) { double lonA, lonB; double latA, latB; lonA = LocationA.GetLongitudeEastPositive(); lonB = LocationB.GetLongitudeEastPositive(); latA = LocationA.GetLatitudeNorthPositive(); latB = LocationB.GetLatitudeNorthPositive(); GPLocation newLoc = new GPLocation(); newLoc.setTimeZone(TimezoneStart ? LocationA.getTimeZone() : LocationB.getTimeZone()); newLoc.setLongitudeEastPositive(lonA + (lonB - lonA) * ratio); newLoc.setLatitudeNorthPositive(latA + (latB - latA) * ratio); newLoc.SetAltitude(0); return(newLoc); }
/// <summary> /// Take an amount from each side to move on the path that's /// a ratio of the ant counts on either side, up to the capacity. /// </summary> public void PathUpdate() { int fromSideA = 0; int fromSideB = 0; float ratio = 0f; int capThisTick = CapPerTick; // Take ratio of ants from both directions if (waitingOnSideA.Count == 0 && waitingOnSideB.Count == 0 && travelingOnSideA.Count == 0 && travelingOnSideB.Count == 0) { // Do nothing if there are no ants here, update only if neede if (capTickAverage != 0f) { capTickAverage = 0f; UpdateText(); } return; } if (waitingOnSideA.Count == 0 && waitingOnSideB.Count == 0) { // StopAllCoroutines(); } else if (waitingOnSideA.Count == 0 || waitingOnSideB.Count == 0) { fromSideA = (waitingOnSideA.Count == 0) ? 0 : capThisTick; fromSideB = (fromSideA == 0) ? capThisTick : 0; } else if (waitingOnSideB.Count < waitingOnSideA.Count) { ratio = ((float)waitingOnSideB.Count) / ((float)waitingOnSideA.Count); fromSideB = Mathf.FloorToInt(ratio * capThisTick); fromSideA = capThisTick - fromSideB; } else { ratio = ((float)waitingOnSideA.Count) / ((float)waitingOnSideB.Count); fromSideA = Mathf.FloorToInt(ratio * capThisTick); fromSideB = capThisTick - fromSideA; } // Move along traveling Queue of ants for (int i = travelingOnSideA.Count - 1; i >= 0; i--) { travelingOnSideA[i].travelTimeLeft -= GameManager.secondsPerGameTick; if (travelingOnSideA[i].travelTimeLeft < float.Epsilon) { LocationB.Accept(travelingOnSideA[i]); travelingOnSideA.RemoveAt(i); } } for (int i = travelingOnSideB.Count - 1; i >= 0; i--) { travelingOnSideB[i].travelTimeLeft -= GameManager.secondsPerGameTick; if (travelingOnSideB[i].travelTimeLeft < float.Epsilon) { LocationA.Accept(travelingOnSideB[i]); travelingOnSideB.RemoveAt(i); } } if (travelingOnSideA.Count > 0) { animationTravelA.enabled = true; } else { animationTravelA.enabled = false; } if (travelingOnSideB.Count > 0) { animationTravelB.enabled = true; } else { animationTravelB.enabled = false; } if (fromSideA > waitingOnSideA.Count) { fromSideA = waitingOnSideA.Count; } if (fromSideB > waitingOnSideB.Count) { fromSideB = waitingOnSideB.Count; } // Move ants to traveling queues Ant tempAnt; for (int i = 0; i < fromSideA; i++) { tempAnt = waitingOnSideA.Dequeue(); tempAnt.travelTimeLeft = secForAnt; travelingOnSideA.Add(tempAnt); } for (int i = 0; i < fromSideB; i++) { tempAnt = waitingOnSideB.Dequeue(); tempAnt.travelTimeLeft = secForAnt; travelingOnSideB.Add(tempAnt); } // Calculate Exponential Moving Average of capacity per tick capTickAverage = (ExpRollingFilterAlpha * (fromSideA + fromSideB)) + (1.0f - ExpRollingFilterAlpha) * capTickAverage; UpdateText(); }