public void GeneralRegionSort(double horizon) { SatelliteVLEO[] nearzone = new SatelliteVLEO[nearestcount]; SatelliteVLEO[] farzone = new SatelliteVLEO[nearestcount]; nearcount = 0; int farcount = 0; for (int i = 0; i < nearestcount; i++) { float dist = Dist(nearestsats [i]); if (dist < horizon) { nearzone [nearcount++] = nearestsats [i]; } else { farzone [farcount++] = nearestsats [i]; } } for (int i = 0; i < nearcount; i++) { nearestsats [i] = nearzone [i]; } for (int i = 0; i < farcount; i++) { nearestsats[i + nearcount] = farzone[i]; } }
void Cache(SatelliteVLEO s) { cachedsats [cachenext] = s; cachenext = (cachenext + 1) % cachesize; if (cachedcount < cachesize) { cachedcount++; } }
bool PreAssign(SatelliteVLEO s) { if (preassignedcount == 5 || s.preassignedcount == 5 || IsPreAssigned(s)) { return(false); } Debug.Assert(s.IsPreAssigned(this) == false); SimplePreAssign(s); s.SimplePreAssign(this); return(true); }
bool IsPreAssigned(SatelliteVLEO s) { for (int i = 0; i < preassignedcount; i++) { if (preassignedsats [i] == s) { return(true); } } return(false); }
public bool ProvAssign(SatelliteVLEO s) { if (provcount == 10 || assignedcount == 5 || IsAssigned(s) || orbitnum == s.orbitnum) { return(false); } Debug.Assert(!IsAssigned(s)); provisionalsats [provcount] = s; provcount++; return(true); }
void CreateSat(int sat_id, int plane_id, float anomaly) { if (orbits[plane_id] == null) { return; } float inclination = plane_inclination [plane_id]; float altitude = plane_altitude [plane_id] + 6371f; GameObject orbit = orbits [plane_id]; SatelliteVLEO newsat; int alt_in_km = (int)(plane_altitude [plane_id]); if (plane_altitude [plane_id] < 500) { newsat = new SatelliteVLEO(satcount, 1, 1, transform, orbit, anomaly, maxlasers, maxsats, 0f, 1, 1, altitude, alt_in_km, satellite_vleo, laser); } else if (plane_altitude [plane_id] < 600) { return; newsat = new SatelliteVLEO(satcount, 1, 1, transform, orbit, anomaly, maxlasers, maxsats, 0f, 1, 1, altitude, alt_in_km, satellite_low, laser); } else if (plane_altitude [plane_id] < 1200) { return; newsat = new SatelliteVLEO(satcount, 1, 1, transform, orbit, anomaly, maxlasers, maxsats, 0f, 1, 1, altitude, alt_in_km, satellite_high, laser); } else { return; newsat = new SatelliteVLEO(satcount, 1, 1, transform, orbit, anomaly, maxlasers, maxsats, 0f, 1, 1, altitude, alt_in_km, satellite_polar, laser); } if (firstsat[alt_in_km] == -1) { firstsat[alt_in_km] = sat_id; } if (sat_id > lastsat[alt_in_km]) { lastsat[alt_in_km] = sat_id; } //print (sat_id); satlist [sat_id] = newsat; satcount++; }
public void ColourLink(SatelliteVLEO nextsat, Material mat) { for (int lc = 0; lc < maxlasers; lc++) { if (laseron [lc]) { if (laserdsts [lc] == nextsat) { LaserScript ls = (LaserScript)lasers [lc].GetComponent(typeof(LaserScript)); ls.SetMaterial(mat); } } } }
void CreateSats(int num_orbits, int num_sats, float inclination, float plane0_raan, float sat_phase_offset, float sat_phase_stagger, double period, float altitude) { float orbit_angle_step = 360f / num_orbits; //print ("CreateSats: num_orbits:" + num_orbits.ToString() + " num_sats:" + num_sats.ToString() // + " inclinations:" + inclination.ToString() + " raan:" + plane0_raan.ToString() + "\n"); for (int i = 0; i < num_orbits; i++) { //Quaternion q = Quaternion.Euler(new Vector3(0f, i*11.25f, 53f)); orbits[count] = (GameObject)Instantiate(orbit, transform.position, transform.rotation); orbits[count].transform.RotateAround(Vector3.zero, Vector3.forward, inclination); float orbit_angle = plane0_raan + i * orbit_angle_step; orbits[count].transform.RotateAround(Vector3.zero, Vector3.up, orbit_angle); orbitaxes [count] = Quaternion.Euler(0, orbit_angle, 0) * (Quaternion.Euler(0, 0, inclination) * Vector3.up); orbitalperiod [count] = period; orbits[count].transform.localScale = new Vector3(altitude, altitude, altitude); for (int s = 0; s < num_sats; s++) { double sat_angle_step = 360f / num_sats; double sat_angle = (-1f * sat_phase_offset * sat_angle_step) + (i * sat_angle_step * sat_phase_stagger) + (s * sat_angle_step); SatelliteVLEO newsat; if (altitude < 6371f + 600f) { newsat = new SatelliteVLEO(satcount, s, i, transform, orbits [count], sat_angle, maxlasers, maxsats, sat_phase_stagger, num_sats, num_orbits, altitude, 550, satellite_low, laser); } else if (inclination > 54f) { newsat = new SatelliteVLEO(satcount, s, i, transform, orbits [count], sat_angle, maxlasers, maxsats, sat_phase_stagger, num_sats, num_orbits, altitude, 1100, satellite_polar, laser); } else { newsat = new SatelliteVLEO(satcount, s, i, transform, orbits [count], sat_angle, maxlasers, maxsats, sat_phase_stagger, num_sats, num_orbits, altitude, 1100, satellite_high, laser); } satlist [satcount] = newsat; satcount++; } count++; } }
public bool InNearest(SatelliteVLEO s) { if (bubblecount < 3) { return(false); } for (int i = 0; i < 3; i++) { if (nearestsats [i] == s) { return(true); } } return(false); }
// find the closest sat we've not already got a laser pointed at public void FindClosest() { int i = 0; while (true) { SatelliteVLEO s = nearestsats [i]; if (!IsAssigned(s)) { if (satid == 13240) { Debug.Log("Closest: " + s.satid.ToString()); } closest = s; break; } i++; } }
/* As the list is roughly sorted, we normally only need to re-sort the first few items */ public void QuickBubble(int sortedrange) { float prevdist = Dist(nearestsats [sortedrange]); for (int i = sortedrange - 1; i >= 0; i--) { float dist = Dist(nearestsats [i]); if (prevdist < dist) { SatelliteVLEO tmp = nearestsats [i]; nearestsats [i] = nearestsats [i + 1]; nearestsats [i + 1] = tmp; } else { prevdist = dist; } } }
public void FinalizeLasers(float speed, Material lineMaterial, Material newLineMaterial) { //if (satid != 158) // return; // Turn off lasers that are no longer assigned to the same target for (int lc = 0; lc < maxlasers; lc++) { if (laseron [lc]) { if (!IsAssigned(laserdsts [lc])) { // laser will need to be reassigned laseron[lc] = false; } } } for (int i = 0; i < assignedcount; i++) { SatelliteVLEO sat = assignedsats [i]; if (!WasAssigned(sat)) { /* destination is a new one - find a laser */ int lasernum = FindFreeLaser(); laseron [lasernum] = true; lasertimes [lasernum] = Time.time; laserdsts [lasernum] = sat; } } int oncount = 0; for (int lc = 0; lc < maxlasers; lc++) { if (laseron [lc]) { oncount++; LaserScript ls = (LaserScript)lasers [lc].GetComponent(typeof(LaserScript)); Vector3 midpoint = (position() + laserdsts [lc].position()) / 2; Debug.Assert(this != laserdsts [lc]); if (position() == laserdsts [lc].position()) { Debug.Log("Same pos"); Debug.Log("Me: " + satid.ToString() + " Him: " + laserdsts [lc].satid.ToString()); Debug.Log("My pos: " + position().ToString() + " His pos: " + laserdsts [lc].position().ToString()); } Debug.Assert(position() != laserdsts [lc].position()); ls.SetPos(position(), laserdsts [lc].position()); if (Time.time - lasertimes [lc] > 5f / speed) { if (glow) { ls.SetMaterial(lineMaterial); } } else { ls.SetMaterial(newLineMaterial); } } else { LaserScript ls = (LaserScript)lasers [lc].GetComponent(typeof(LaserScript)); ls.SetPos(position(), position()); } } }
public void AddSat(SatelliteVLEO newsat) { nearestsats[nearestcount] = newsat; nearestcount++; }
public void SimpleAssign(SatelliteVLEO s) { assignedsats [assignedcount] = s; assignedcount++; }
public float Dist(SatelliteVLEO s) { return(Vector3.Distance(position(), s.position())); }
public void SimplePreAssign(SatelliteVLEO s) { preassignedsats [preassignedcount] = s; preassignedcount++; }
// connect the sats in a list along an orbit public void SetPrev(SatelliteVLEO prev) { prevsat = prev; prev.nextsat = this; }