/// <summary> /// Visual indication of currently selected attacker in the plan /// </summary> public void SetActiveAttacker(AttackPlanFrom activeAttacker) { if (_activeAttacker != null) { _activeAttacker.BackColor = SystemColors.Control; } AttackPlanFromControl attackerControl = GetControlForAttackPlan(activeAttacker); if (attackerControl != null) { attackerControl.BackColor = SystemColors.ControlDark; _activeAttacker = attackerControl; DistanceContainer.ScrollControlIntoView(_activeAttacker); } }
public DistanceContainer(float dist, DistanceContainer p, Vector3 point){ distance = dist; prev = p; pt = point; }
public void loadRoutes(){ allLoadedPaths = new List<LoadedPath>(); for(int i = 0; i < allPoints.Count; i++){ for(int i2 = 0; i2 < allPoints.Count; i2++){ if(i != i2){ Vector3 pt1 = allPoints[i]; Vector3 pt2 = allPoints[i2]; // set all distances to infinity initially DistanceContainer dc1 = null; DistanceContainer dc2 = null; DistanceContainer[] distances = new DistanceContainer[allPoints.Count]; for(int i3 = 0; i3 < allPoints.Count; i3++){ distances[i3] = new DistanceContainer(Mathf.Infinity, null, allPoints[i3]); if(i3 == i){ dc1 = distances[i3]; } if(i3 == i2){ dc2 = distances[i3]; } } distances[i].distance = 0; distances[i].prev = distances[i]; List<int> removedIndices = new List<int>(); DistanceContainer u = dc1; int breakCount = 0; while((removedIndices.Count < allPoints.Count)&&(breakCount < 100)){ breakCount ++; //find the vertex with the smallest distance int index = 0; float currentShortestDist = Mathf.Infinity; for(int i3 = 0; i3 < allPoints.Count; i3++){ if(removedIndices.IndexOf(i3) == -1){ if(distances[i3].distance < currentShortestDist){ currentShortestDist = distances[i3].distance; u = distances[i3]; index = i3; } } } if(currentShortestDist == Mathf.Infinity){ break; } removedIndices.Add(index); if(u.pt != pt2){ //for each neighbour of u, calculate new distance for(int i3 = 0; i3 < allPoints.Count; i3++){ Vector3 ptTemp = allPoints[i3]; if(!getIntersected(u.pt, ptTemp)){ float alt = currentShortestDist + Vector3.Distance(u.pt, ptTemp); if(alt < distances[i3].distance){ distances[i3].distance = alt; distances[i3].prev = u; } } } }else{ break; } } // iterate backwards through distance containers to get path List<Vector3> sequence = new List<Vector3>(); if(u.pt == pt2){ sequence.Add(u.pt); while((u.prev != u)&&(u.prev != null)){ u = u.prev; sequence.Add(u.pt); } sequence.Reverse(); } if(breakCount == 100){ Debug.Log("Failed to calculate paths within enough iterations. Sequence has length: " + sequence.Count); }else{ Debug.Log("Calculated path. Sequence has length: " + sequence.Count); } allLoadedPaths.Add(new LoadedPath(pt1, pt2, sequence)); } } } }
public MyLocationListener() { _distanceContainer = new DistanceContainer(); _speedContainer = new SpeedContainer(); }