public void UpdateFindingDistanceMusic(Constellation display, GameObject currentFocus) { float distanceA = 40f; float distanceB = 20f; float distanceC = 10f; AudioSource beat = findMusicCollection.GetComponent <AudioSource>(); if (lessThanDistance(display, currentFocus, distanceA)) { beat.mute = false; if (lessThanDistance(display, currentFocus, distanceC)) { beat.pitch = 2.5f; } else if (lessThanDistance(display, currentFocus, distanceB)) { beat.pitch = 2f; } else { beat.pitch = 1.5f; } } else { beat.mute = true; } }
public ConstellationEditDialog(string dialogTitle, Constellation thisConstellation, Callback <Constellation> creationCallback, Callback <Constellation, short> updateCallback) : base("constellationEdit", dialogTitle, 0.5f, //x 0.5f, //y 250, //width 170, //height new DialogOptions[] { DialogOptions.HideCloseButton }) { this.creationCallback = creationCallback; this.updateCallback = updateCallback; this.existingConstellation = thisConstellation; if (this.existingConstellation != null) { this.constellColor = this.existingConstellation.color; this.description = Localizer.Format("#CNC_ConstellationEdit_description2", this.existingConstellation.name); //string.Format("You are editing Constellation '{0}'.", ) this.actionButtonText = Localizer.Format("#CNC_Generic_UpdateButton"); //"Update" } this.GetInputLocks(); }
//New Branches - Barron and Painting public void NewBranche(Constellation constellation) { currentConstellation?.gameObject.SetActive(false); currentConstellation = constellation; constellations.Add(constellation); }
private void ParseConstellations() { TextAsset asset = Resources.Load("constellations") as TextAsset; string fs = asset.text; var json = JSON.Parse(fs); List <Constellation> constellations = new List <Constellation> (); foreach (KeyValuePair <string, JSONNode> item in json.AsObject) { Constellation newConstellation = new Constellation(); newConstellation.SetAbbr(item.Key); var constellation = JSON.Parse(item.Value.ToString()); foreach (var line in constellation.AsArray) { var segment = JSON.Parse(line.ToString()).AsArray; int[] newLine = new int[2] { segment[0].AsInt, segment[1].AsInt }; newConstellation.AddLine(newLine); } constellations.Add(newConstellation); } skyModel.SetConstellations(constellations); }
static bool GenerateConstellationConnection(Constellation constellationA, Constellation constellationB, List <Constellation> constellations, List <ConstellationConnection> connections) { var possibleConnections = new List <ConstellationConnection>(); for (int i = 0; i < constellationA.StarPositions.Count; i++) { for (int j = 0; j < constellationB.StarPositions.Count; j++) { var distance = (constellationA.StarPositions[i] - constellationB.StarPositions[j]).Length(); possibleConnections.Add(new ConstellationConnection { C1 = constellationA, C2 = constellationB, I1 = i, I2 = j, Distance = distance }); } } possibleConnections.Sort(); foreach (var potentialConnection in possibleConnections) { if (!ConnectionIntersects(constellations, connections, potentialConnection)) { connections.Add(potentialConnection); return(true); } } return(false); }
public void MergeWith(Constellation other) { foreach (var point in other.points) { points.Add(point); } }
// Function to get random point on static (non-animated) constellation mesh // >> MeshHelper script shouldn't know about larger game public Vector3 GetRandomPointOnAnimatedConstellationMesh(Mesh mesh, Constellation con, float uniqueVal) { //Mesh mesh = Constellation.GetComponentInChildren<MeshFilter>().sharedMesh; // get random triangle in mesh int triIndex = GetRandomTriangle(mesh, uniqueVal); Vector3 a = mesh.vertices[mesh.triangles[triIndex * 3]]; Vector3 b = mesh.vertices[mesh.triangles[triIndex * 3 + 1]]; Vector3 c = mesh.vertices[mesh.triangles[triIndex * 3 + 2]]; // BUT this doesn't account for Mesh's position, or rotation Vector3 pointOnMesh = a + uniqueVal * (b - a) + (1 - uniqueVal) * (c - a); // Note: no need to scale for animated mesh // rotate by rotation pointOnMesh = con.transform.rotation * pointOnMesh; // translate by position // > shifts from model to world space pointOnMesh = pointOnMesh + con.transform.position; return(pointOnMesh); }
/// <summary> /// Replace one frequency in the particular antenna /// </summary> public void updateFrequency(CNCAntennaPartInfo partInfo, short newFrequency) { if (!Constellation.isFrequencyValid(newFrequency)) { CNCLog.Error("New frequency {0} is out of the range [0,{1}]!", newFrequency, short.MaxValue); return; } partInfo.frequency = newFrequency; if (this.Vessel.loaded) { partInfo.partReference.FindModuleImplementing <CNConstellationAntennaModule>().Frequency = newFrequency; } else { var cncAntMod = partInfo.partSnapshotReference.FindModule("CNConstellationAntennaModule"); if (cncAntMod != null) { cncAntMod.moduleValues.SetValue("Frequency", newFrequency); } } CNCLog.Verbose("Update the antenna of CommNet vessel '{0}' to {1}", this.Vessel.GetName(), newFrequency); }
public static Constellation Gen(string name, int numberOfStars) { NumberOfStars = numberOfStars; Constellation = new Constellation(name); NumMultiConnections = 0; NumAttempts = 0; //while (NumMultiConnections < 3 && NumAttempts <= 0) //{ NumMultiConnections = 0; NumAttempts++; StargateConnections = new Dictionary <Vector2Int, SolarSystemConnections>(); Positions = new Point[NumberOfStars]; Network = new float[NumberOfStars, NumberOfStars]; SetNet(Network, Positions); Prims(); AddStargates(); //} return(Constellation); }
// 根据出生日期获得星座信息 static Constellation GetConstellation(int birthMonth, int birthDate) { float birthdayF = birthMonth == 1 && birthDate < 20 ? 13 + birthDate / 100f : birthMonth + birthDate / 100f; float[] bound = { 1.20F, 2.20F, 3.21F, 4.21F, 5.21F, 6.22F, 7.23F, 8.23F, 9.23F, 10.23F, 11.21F, 12.22F, 13.20F }; Constellation[] constellations = new Constellation[12]; for (int i = 0; i < constellations.Length; i++) { constellations[i] = (Constellation)(i + 1); } for (int i = 0; i < bound.Length - 1; i++) { float b = bound[i]; float nextB = bound[i + 1]; if (birthdayF >= b && birthdayF < nextB) { return(constellations[i]); } } return(Constellation.Acrab); }
public void Merge(Constellation other) { foreach (var star in other.stars) { Add(star); } }
private void updateClick() { try { try { short userFreq = short.Parse(frequencyInput.uiItem.GetComponent <TMP_InputField>().text); //Check frequency if (userFreq < 0) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_negative"));//"Frequency cannot be negative" } else if (!Constellation.isFrequencyValid(userFreq)) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_Valid", short.MaxValue));//"Frequency must be between 0 and " + } //ALL OK if (!this.cncVessel.isFreqListEditable()) { return; } //update all antennas to new freq for (int i = 0; i < this.antennas.Count; i++) { CNCAntennaPartInfo thisAntenna = this.antennas[i]; this.cncVessel.toggleAntenna(thisAntenna, true); if (thisAntenna.frequency != userFreq) // update each antenna to user freq { this.cncVessel.updateFrequency(thisAntenna, userFreq); } } this.cncVessel.rebuildFreqList(); //if membership option is not enabled, add public freq of same comm power if (!membershipOption && userFreq != CNCSettings.Instance.PublicRadioFrequency) { double commPower = this.cncVessel.getMaxComPower(userFreq); this.cncVessel.addToFreqList(CNCSettings.Instance.PublicRadioFrequency, commPower); } actionCallbacks[0](); } catch (FormatException e) { throw new FormatException(Localizer.Format("#CNC_CheckFrequency_Format"));//"Frequency must be numeric only" } catch (OverflowException e) { throw new OverflowException(Localizer.Format("#CNC_CheckFrequency_Overflow", short.MaxValue));//string.Format("Frequency must be equal to or less than {0}", ) } } catch (Exception e) { ScreenMessage msg = new ScreenMessage("<color=red>" + e.Message + "</color>", CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage(msg); } }
private async Task <bool> LoadConstellation() { // first get the safe file "state" var fullPath = Path.Combine(UnityGame.UserDataPath, Plugin.Name, "state"); // if it doesn't exist, use a constellation if (!File.Exists(fullPath)) { fullPath = Path.Combine(UnityGame.UserDataPath, Plugin.Name, "Constellations", "Default"); } // if this also doesn't exist, return if (!File.Exists(fullPath)) { return(false); } var text = await CommonExtensions.ReadFileTextAsync(fullPath); var constellation = Constellation.FromStringAsync("state", text); _pillowSpawner.SetConstellation(constellation, false); return(true); }
/// <summary> /// Action to remove the constellation from the record and save /// </summary> private void deleteConstellation(Constellation deletedConstellation) { if (deleteConstellationGUIRow(deletedConstellation) >= 0) { CNCCommNetScenario.Instance.constellations.RemoveAt(CNCCommNetScenario.Instance.constellations.FindIndex(x => x.frequency == deletedConstellation.frequency)); short publicFrequency = CNCSettings.Instance.PublicRadioFrequency; List <CNCCommNetVessel> affectedVessels = CNCCommNetScenario.Instance.getCommNetVessels().FindAll(x => x.getFrequencyList().Contains(deletedConstellation.frequency)); for (int i = 0; i < affectedVessels.Count; i++) { affectedVessels[i].replaceAllFrequencies(deletedConstellation.frequency, publicFrequency); affectedVessels[i].OnAntennaChange(); } if (affectedVessels.Count > 0) { updateConstellationGUIRow(publicFrequency, -1); } List <CNCCommNetHome> affectedStations = CNCCommNetScenario.Instance.groundStations.FindAll(x => x.getFrequencyList().Contains(deletedConstellation.frequency)); for (int i = 0; i < affectedStations.Count; i++) { affectedStations[i].deleteFrequency(deletedConstellation.frequency); } } }
private int deleteConstellationGUIRow(Constellation thisConstellation) { if (this.currentContentType != ContentType.CONSTELLATIONS) { return(-1); } List <DialogGUIBase> rows = contentLayout.children; for (int i = 2; i < rows.Count; i++) { DialogGUIBase thisRow = rows[i]; if (thisRow.OptionText.Equals(thisConstellation.frequency.ToString())) { rows.RemoveAt(i); // drop from the scrolllist rows for (int j = thisRow.children.Count - 1; j >= 0; j--) // necessary to free memory up { thisRow.children[j].uiItem.gameObject.DestroyGameObjectImmediate(); } thisRow.uiItem.gameObject.DestroyGameObjectImmediate(); return(i); } } return(-1); }
/// <summary> /// Replace one frequency in all antennas /// </summary> public void replaceAllFrequencies(short oldFrequency, short newFrequency) { if (!Constellation.isFrequencyValid(newFrequency)) { CNCLog.Error("New frequency {0} is out of the range [0,{1}]!", newFrequency, short.MaxValue); return; } if (this.Vessel.loaded) { List <CNConstellationAntennaModule> mods = this.Vessel.FindPartModulesImplementing <CNConstellationAntennaModule>().FindAll(x => x.Frequency == oldFrequency); for (int i = 0; i < mods.Count; i++) { mods[i].Frequency = newFrequency; } } else { for (int i = 0; i < this.vessel.protoVessel.protoPartSnapshots.Count; i++) { ProtoPartModuleSnapshot cncAntMod = this.vessel.protoVessel.protoPartSnapshots[i].FindModule("CNConstellationAntennaModule"); if (cncAntMod != null && short.Parse(cncAntMod.moduleValues.GetValue("Frequency")) == oldFrequency) { cncAntMod.moduleValues.SetValue("Frequency", newFrequency); } } } getAllAntennaInfo(true); CNCLog.Verbose("Update all occurrences of frequency {1} in CommNet vessel '{0}' to {2}", this.Vessel.GetName(), oldFrequency, newFrequency); }
private DialogGUIHorizontalLayout createConstellationRow(Constellation thisConstellation) { Color color = Constellation.getColor(thisConstellation.frequency); DialogGUIImage colorImage = new DialogGUIImage(new Vector2(32, 32), Vector2.zero, thisConstellation.color, colorTexture); DialogGUILabel constNameLabel = new DialogGUILabel(thisConstellation.name, 170, 12); DialogGUILabel freqLabel = new DialogGUILabel(Localizer.Format("#CNC_Generic_FrequencyLabel") + string.Format(": <color={0}>{1}</color>", UIUtils.colorToHex(color), thisConstellation.frequency), 100, 12); //Frequency DialogGUILabel numSatsLabel = new DialogGUILabel(Localizer.Format("#CNC_ConstellationControl_numSatsLabel", Constellation.countVessels(thisConstellation)), 75, 12); //string.Format("{0} vessels", ) DialogGUIButton updateButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_Editbutton"), delegate { editConstellationClick(thisConstellation); }, 50, 32, false); //"Edit" DialogGUIToggleButton toggleButton = new DialogGUIToggleButton(thisConstellation.visibility, Localizer.Format("#CNC_Generic_Mapbutton"), delegate { toggleConstellationVisibility(thisConstellation); }, 45, 32); //"Map" DialogGUIBase[] rowGUIBase = new DialogGUIBase[] { colorImage, constNameLabel, freqLabel, numSatsLabel, toggleButton, updateButton, null }; if (thisConstellation.frequency == CNCSettings.Instance.PublicRadioFrequency) { rowGUIBase[rowGUIBase.Length - 1] = new DialogGUIButton(Localizer.Format("#CNC_Generic_Resetbutton"), resetPublicConstClick, 60, 32, false);//"Reset" } else { rowGUIBase[rowGUIBase.Length - 1] = new DialogGUIButton(Localizer.Format("#CNC_Generic_DeleteButton"), delegate { deleteConstellationClick(thisConstellation); }, 60, 32, false);//"Delete" } DialogGUIHorizontalLayout constellationGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, rowGUIBase); constellationGroup.SetOptionText(thisConstellation.frequency.ToString()); //for quick identification return(constellationGroup); }
private static async Task SeedConstellationsAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger) { await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths.ConstellationsCsvFilePath)) { if (string.IsNullOrWhiteSpace(line)) { continue; } var lineArgs = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries); var regionIdParseSuccess = long.TryParse(lineArgs[0], out var regionId); var constellationParseSuccess = long.TryParse(lineArgs[1], out var constellationId); var constellationName = lineArgs[2]; if (!regionIdParseSuccess || !constellationParseSuccess) { logger.LogWarning(string.Format(DatabaseConstants.SeedingConstants.ConstellationErrorParseMessage, constellationName)); logger.LogWarning(line); continue; } var constellation = new Constellation() { RegionId = regionId, Id = constellationId, Name = constellationName, }; await dbContext.AddAsync(constellation); } await dbContext.SaveChangesWithExplicitIdentityInsertAsync(nameof(EveEchoesPlanetaryProductionApiDbContext .Constellations)); }
// C-tors public Nebula(string name, double distance, Constellation starGroup = Constellation.Orion) { Name = name; Distance = distance; StarGroup = starGroup; BodyType = BodyType.Nebula; }
public void InitializeConstellation(ConstellationScriptData[] constellationScripts) { Entries = new List <Node <INode> >(); BrightEntriesInfos = new List <BrightEntryInfos>(); ExitNodes = new List <IExitNode>(); parameters = new List <IReceiver>(); if (isInitialized) // do not initialize twice { return; } nodesFactory = new NodesFactory(constellationScripts); var parametersCounter = 0; var entryCounter = 0; var exitCounter = 0; constellation = new Constellation(UnityEngine.JsonUtility.FromJson <ConstellationScriptData>(constellationNodeData.Value.GetString()), nodesFactory, (newNode, node) => { if (newNode.NodeType is IExitNode) { ExitNodes.Add(newNode.NodeType as IExitNode); if (newNode.NodeType is IBrightExitNode) { (newNode.NodeType as IBrightExitNode).SubscribeReceiver(this, exitCounter); } exitCounter++; } if (newNode.Name == CoreNodes.Entry.NAME || newNode.Name == CoreNodes.BrightEntry.NAME) { if (newNode.Name == CoreNodes.BrightEntry.NAME) { BrightEntriesInfos.Add(new BrightEntryInfos(newNode, entryCounter)); } entryCounter++; Entries.Add(newNode); } if (newNode.NodeType.NodeName() == Parameters.ValueParameter.NAME || newNode.NodeType.NodeName() == Parameters.WordParameter.NAME) { parameters.Add(newNode.NodeType as IReceiver); } if (IsAttribute(node) && NodeParameters[parametersCounter] != null) { IParameter nodeParameter = newNode.NodeType as IParameter; if (node.Name != "ObjectParameter" && parametersCounter < NodeParameters.Count) { nodeParameter.SetParameter(NodeParameters[parametersCounter]); } parametersCounter++; } }); constellation.Initialize(System.Guid.NewGuid().ToString(), nameParameter.Value.GetString()); isInitialized = true; }
public static string GetConstellation(double ra2000Hrs, double dec2000Deg, out string abbreviatedName) { double rA = ra2000Hrs * 15 * Math.PI / 180; double dec = dec2000Deg * Math.PI / 180; PrecessStartToEnd(2451545.0, 2405890.5, ref rA, ref dec); rA = (rA * 57.295779513082323) / 15.0; dec *= 57.295779513082323; int index = -1; do { index++; }while (s_ConstellationBoundaries[index].Dec > dec); do { index--; do { index++; }while (s_ConstellationBoundaries[index].RaTo <= rA); index--; do { index++; }while (s_ConstellationBoundaries[index].RaFrom > rA); }while (s_ConstellationBoundaries[index].RaTo <= rA); Constellation constellation = s_Constellations[s_ConstellationBoundaries[index].ConstellationIndex - 1]; abbreviatedName = constellation.Abbreviation; return(constellation.Name); }
private void ListPanelAddButton_Click(object sender, RoutedEventArgs e) { SpaceObject newObj = null; switch (currenObjectsPaneltType) { case ObjectsPanelType.Constellations: newObj = new Constellation(); break; case ObjectsPanelType.Planets: newObj = new Planet(); break; case ObjectsPanelType.Stars: newObj = new Star(); break; } newObj.Universe = _universe; OpenInfoWindow(newObj, delegate() { _universe.Add(newObj); sky.ItemsSource = _universe; }); }
public Constellation GetConstellationById(int id) { var constellation = _context.Constellations.FirstOrDefault(x => x.Id == id); if (constellation == null || constellation.PassedMoreThan() || constellation.Name == "Temp") { var esiResult = _universeApi.GetUniverseConstellationsConstellationId(id, "en-us", null, null, "en-us"); if (esiResult.RegionId.HasValue) { _regionService.GetRegionById(esiResult.RegionId.Value); } if (constellation == null) { constellation = new Constellation { Id = id, Name = esiResult.Name, RegionId = esiResult.RegionId.Value }; _context.Constellations.Add(constellation); } else { constellation.Name = esiResult.Name; constellation.RegionId = esiResult.RegionId.Value; } _context.SaveChanges(); } return(constellation); }
private void updateConstellationGUIRow(short updatedfrequency, short previousFrequency) { if (this.currentContentType != ContentType.CONSTELLATIONS) { return; } List <DialogGUIBase> rows = contentLayout.children; for (int i = 2; i < rows.Count; i++) { DialogGUIBase thisRow = rows[i]; if (thisRow.OptionText.Equals(updatedfrequency.ToString()) || thisRow.OptionText.Equals(previousFrequency.ToString())) { DialogGUIImage colorImage = thisRow.children[0] as DialogGUIImage; DialogGUILabel nameLabel = thisRow.children[1] as DialogGUILabel; DialogGUILabel freqLabel = thisRow.children[2] as DialogGUILabel; DialogGUILabel vesselLabel = thisRow.children[3] as DialogGUILabel; Constellation updatedConstellation = CNCCommNetScenario.Instance.constellations.Find(x => x.frequency == updatedfrequency); colorImage.uiItem.GetComponent <RawImage>().color = updatedConstellation.color; nameLabel.SetOptionText(updatedConstellation.name); freqLabel.SetOptionText(Localizer.Format("#CNC_Generic_FrequencyLabel") + string.Format(": <color={0}>{1}</color>", UIUtils.colorToHex(updatedConstellation.color), updatedConstellation.frequency)); //Frequency vesselLabel.SetOptionText(Localizer.Format("#CNC_ConstellationControl_numSatsLabel", Constellation.countVessels(updatedConstellation))); // + " vessels" thisRow.SetOptionText(updatedConstellation.frequency.ToString()); break; } } }
/// <summary> /// 根据出生日期获得星座信息 /// </summary> public static string GetConstellation(this DateTime birthdate) { var rtn = Constellation.Acrab; float birthdayF = birthdate.Month == 1 && birthdate.Day < 20 ? 13 + birthdate.Day / 100f : birthdate.Month + birthdate.Day / 100f; float[] bound = { 1.20F, 2.20F, 3.21F, 4.21F, 5.21F, 6.22F, 7.23F, 8.23F, 9.23F, 10.23F, 11.21F, 12.22F, 13.20F }; var constellations = new Constellation[12]; for (int i = 0; i < constellations.Length; i++) { constellations[i] = (Constellation)(i + 1); } for (int i = 0; i < bound.Length - 1; i++) { float b = bound[i]; float nextB = bound[i + 1]; if (birthdayF >= b && birthdayF < nextB) { rtn = constellations[i]; } } return(rtn.ToDescription()); }
static List <ConstellationConnection> ConnectNearestConstellations(List <Constellation> constellations) { var constellationConnections = new List <ConstellationConnection>(); var connectedConstellations = new HashSet <Constellation> { constellations[0] }; while (connectedConstellations.Count < constellations.Count) { var minDistance = float.MaxValue; Constellation constellationToConnect = null; Constellation newConnectedConstellation = null; foreach (var connectedConstellation in connectedConstellations) { foreach (var notConnectedConstellation in constellations.Where(constellation => !connectedConstellations.Contains(constellation))) { var centerDistance = (connectedConstellation.Center - notConnectedConstellation.Center).Length(); if (centerDistance < minDistance) { minDistance = centerDistance; constellationToConnect = connectedConstellation; newConnectedConstellation = notConnectedConstellation; } } } connectedConstellations.Add(newConnectedConstellation); if (!GenerateConstellationConnection(constellationToConnect, newConnectedConstellation, constellations, constellationConnections)) { GD.PrintErr("Possibly could not connect all constellations"); } } return(constellationConnections); }
public FramingConstellation(Constellation constellation, ViewportFoV viewport) { this.constellation = constellation; Id = constellation.Id; Name = constellation.Name; var constellationStartDec = constellation.Stars.Select(m => m.Coords.Dec).Min(); var constellationStopDec = constellation.Stars.Select(m => m.Coords.Dec).Max(); if (constellation.GoesOverRaZero) { double stopRA = double.MaxValue; double startRA = 0; foreach (var star in constellation.Stars) { if (star.Coords.RADegrees > 180) { stopRA = Math.Min(stopRA, star.Coords.RADegrees); } else { startRA = Math.Max(startRA, star.Coords.RADegrees); } } if (stopRA == double.MaxValue) { stopRA = 0; } var distance = startRA + 360 - stopRA; var centerRa = stopRA + distance / 2; if (centerRa > 360) { centerRa -= 360; } constellationCenter = new Coordinates(centerRa, constellationStopDec + (constellationStartDec - constellationStopDec) / 2, Epoch.J2000, Coordinates.RAType.Degrees); } else { var constellationStartRA = constellation.Stars.Select(m => m.Coords.RADegrees).Min(); var constellationStopRA = constellation.Stars.Select(m => m.Coords.RADegrees).Max(); constellationCenter = new Coordinates( constellationStopRA + (constellationStartRA - constellationStopRA) / 2, constellationStopDec + (constellationStartDec - constellationStopDec) / 2, Epoch.J2000, Coordinates.RAType.Degrees); } Points = new HashSet <Tuple <Star, Star> >(); Stars = new HashSet <Star>(); foreach (var star in constellation.Stars) { star.Radius = (-3.375f * star.Mag + 23.25f) / (float)(viewport.VFoVDeg / 8f); } }
// Start is called before the first frame update void Start() { if (_Constelation != null) { _constellation = _Constelation.GetComponent <Constellation>(); } }
/** * Calculates the cost (hamming distance) of using the argument as the * left side dibit for the current node, and recursively finding the * cheapest corresponding right dibit. * * @param leftTest * @return */ public int costTo(Dibit leftTest) { if (isCurrentConnectionCorrect()) { Constellation c = Constellation. fromDibits(leftTest, mConstellation.getRight()); return(mConstellation.costTo(c)); } else { int cheapestCost = 100; //arbitrary foreach (Dibit d in Dibit.values()) { Constellation c = Constellation.fromDibits(leftTest, d); int cost = mConnectedNode.costTo(d) + mConstellation.costTo(c); if (cost < cheapestCost) { cheapestCost = cost; } } return(cheapestCost); } }
///////////////////// // Actions /// <summary> /// Action to reset the public constellation /// </summary> private void resetPublicConstellation() { Constellation publicConstellation = CNCCommNetScenario.Instance.constellations.Find(x => x.frequency == CNCSettings.Instance.PublicRadioFrequency); publicConstellation.name = CNCSettings.Instance.DefaultPublicName; publicConstellation.color = CNCSettings.Instance.DefaultPublicColor; updateConstellation(publicConstellation, CNCSettings.Instance.PublicRadioFrequency); }
static AstroUtilities() { using (Stream resStr = AssemblyHelper.GetEmbededResourceStreamThatClientMustDispose("Tangra.KweeVanWoerden.Resources", "Earth.bin")) using (BinaryReader reader = new BinaryReader(resStr)) { long entriesCount = resStr.Length / EarthAberrationData.REC_LENGTH; s_AberrationArgs = new EarthAberrationData[entriesCount]; for (int i = 0; i < entriesCount; i++) { s_AberrationArgs[i] = new EarthAberrationData(reader); } } using (Stream resStr = AssemblyHelper.GetEmbededResourceStreamThatClientMustDispose("Tangra.KweeVanWoerden.Resources", "Nutation.bin")) using (BinaryReader reader = new BinaryReader(resStr)) { long entriesCount = resStr.Length / EarthNutationData.REC_LENGTH; s_NutationArgs = new EarthNutationData[entriesCount]; for (int i = 0; i < entriesCount; i++) { s_NutationArgs[i] = new EarthNutationData(reader); } } using (Stream resStr = AssemblyHelper.GetEmbededResourceStreamThatClientMustDispose("Tangra.KweeVanWoerden.Resources", "Constellations.bin")) using (TextReader reader = new StreamReader(resStr)) { for (int i = 0; i < 88; i++) { s_Constellations[i] = new Constellation(); s_Constellations[i].Name = reader.ReadLine(); } for (int i = 0; i < 88; i++) s_Constellations[i].Abbreviation = reader.ReadLine(); for (int i = 0; i < 357; i++) { s_ConstellationBoundaries[i] = new ConstellationBoundaryEntry(); s_ConstellationBoundaries[i].RaFrom = float.Parse(reader.ReadLine(), CultureInfo.InvariantCulture); s_ConstellationBoundaries[i].RaTo = float.Parse(reader.ReadLine(), CultureInfo.InvariantCulture); s_ConstellationBoundaries[i].Dec = float.Parse(reader.ReadLine(), CultureInfo.InvariantCulture); s_ConstellationBoundaries[i].ConstellationIndex = int.Parse(reader.ReadLine(), CultureInfo.InvariantCulture); } } }
public void setConstellation(Constellation constellation) { mConstellation = constellation; mCorrect = false; }
public int costTo(Constellation other) { return CONSTELLATION_COSTS[getValue()][other.getValue()]; }
public override void Execute() { int nConstellations; int factorA, factorB, a, b, factor; bool gotMatch; List<Region> neutralRegions = new List<Region>(); List<Region> spawnRegions = new List<Region>(); System.Diagnostics.Trace.WriteLine(this.Name + " - Execute - begin"); //BUILD REGIONS foreach (Color c in Galaxy.Instance.Configuration.shape().regions.Keys) Galaxy.Instance.Regions.Add(new Region(c)); neutralRegions.AddRange(Galaxy.Instance.Regions.FindAll((Region r) => { return !r.isSpawn(); })); spawnRegions.AddRange(Galaxy.Instance.Regions.FindAll((Region r) => { return r.isSpawn(); })); System.Diagnostics.Trace.WriteLine(Galaxy.Instance.Configuration.shape().regions.Keys.Count.ToString() + " theoretical regions"); System.Diagnostics.Trace.WriteLine(Galaxy.Instance.Regions.Count.ToString() + " actual regions"); System.Diagnostics.Trace.WriteLine(spawnRegions.Count.ToString() + " spawn regions"); foreach (Region r in spawnRegions) System.Diagnostics.Trace.WriteLine("-->" + r.Index.ToString() + " containing " + r.Count.ToString()+ " stars"); System.Diagnostics.Trace.WriteLine(neutralRegions.Count.ToString() + " neutral regions"); foreach (Region r in neutralRegions) System.Diagnostics.Trace.WriteLine("-->" + r.Index.ToString() + " containing " + r.Count.ToString() + " stars"); //DETERMINE ACTUAL CONSTELLATIONS NUMBER nConstellations = Galaxy.Instance.Configuration.constellations(); System.Diagnostics.Trace.WriteLine("Configuration requested constellations : " + Galaxy.Instance.Configuration.constellations().ToString()); while ((nConstellations * Settings.Instance.generationConstraints.minStarsPerConstellation) > Galaxy.Instance.Stars.Count) nConstellations--; if (nConstellations <= 0) nConstellations = 1; if (nConstellations < Galaxy.Instance.Configuration.constellations()) { System.Diagnostics.Trace.WriteLine("Min stars per constellation : " + Settings.Instance.generationConstraints.minStarsPerConstellation.ToString()); System.Diagnostics.Trace.WriteLine("Will use only " + nConstellations.ToString() + " constellations"); this.Defects.Add("Number of constellations was limited by stars number"); } //DISTRIBUTE CONSTELLATIONS ACROSS REGIONS if (nConstellations == 1) { System.Diagnostics.Trace.WriteLine("Single Constellation"); Constellation c = new Constellation(); c.AddRange(Galaxy.Instance.Stars); } else if (nConstellations == Galaxy.Instance.Regions.Count) { System.Diagnostics.Trace.WriteLine("One Constellation Per Region"); foreach (Region r in Galaxy.Instance.Regions) { Constellation c = new Constellation(); c.AddRange(r); } } else { System.Diagnostics.Trace.WriteLine("Other Case"); factorA = 0; factorB = 0; gotMatch = false; for (a = 1; a < 20; a++) { for (b = 0; b < 20; b++) { if (a * spawnRegions.Count + b * neutralRegions.Count == nConstellations) { gotMatch = true; factorA = a; factorB = b; } } } if (gotMatch) { System.Diagnostics.Trace.WriteLine("Could find integers A=" + factorA.ToString() + " and B=" + factorB.ToString()); System.Diagnostics.Trace.WriteLine("Allowing A Constellations in each Spawn Region"); System.Diagnostics.Trace.WriteLine("And B Constellation in each Neutral Region"); if (factorA > 0) { foreach (Region r in spawnRegions) { this.MakeConstellations(factorA, r); } } if (factorB > 0) { foreach (Region r in neutralRegions) { this.MakeConstellations(factorB, r); } } } else { System.Diagnostics.Trace.WriteLine("No exact match"); if (nConstellations >= spawnRegions.Count) { System.Diagnostics.Trace.WriteLine("More Constellations than Spawn Regions"); foreach (Region r in spawnRegions) { this.MakeConstellations(1, r); } if (nConstellations - spawnRegions.Count > 0) { List<StarSystem> pool = new List<StarSystem>(); foreach(Region r in neutralRegions) pool.AddRange(r); this.MakeConstellations(nConstellations - spawnRegions.Count, pool); } } else { System.Diagnostics.Trace.WriteLine("Less Constellations than Spawn Regions"); factor = 1; while (factor * nConstellations < spawnRegions.Count) factor++; Region start; Region merge; List<Region> adjacentSpawnRegions = new List<Region>(); List<Region> mergedRegions = new List<Region>(); List<Region> nextStartCandidates = new List<Region>(); List<StarSystem> pool = new List<StarSystem>(); int i; //loop //starting with one random spawn region //merge (factor adjacent spawn regions) into result //make one constellation in result //until remaining spawn regions number less than factor System.Diagnostics.Trace.WriteLine("Using topology to try grouping " + factor.ToString() + " Spawn Regions in each Constellation"); start = spawnRegions.ElementAt(GalaxyGeneratorPlugin.random.Next(spawnRegions.Count)); while ((spawnRegions.Count >= factor) && (start != null) && (Galaxy.Instance.Constellations.Count < nConstellations)) { i = 0; spawnRegions.Remove(start); mergedRegions.Clear(); mergedRegions.Add(start); adjacentSpawnRegions.AddRange(start.adjacentRegions().FindAll((r) => { return r.isSpawn(); })); adjacentSpawnRegions.RemoveAll((r) => { return !spawnRegions.Contains(r); }); for (; (i < factor-1) && (adjacentSpawnRegions.Count > 0); i++) { adjacentSpawnRegions.Clear(); foreach (Region r in mergedRegions) adjacentSpawnRegions.AddRange(r.adjacentRegions()); adjacentSpawnRegions.RemoveAll((r) => { return mergedRegions.Contains(r); }); adjacentSpawnRegions.RemoveAll((r) => { return !r.isSpawn(); }); adjacentSpawnRegions.RemoveAll((r) => { return !spawnRegions.Contains(r); }); if (adjacentSpawnRegions.Count > 0) { merge = adjacentSpawnRegions.ElementAt(GalaxyGeneratorPlugin.random.Next(adjacentSpawnRegions.Count)); mergedRegions.Add(merge); spawnRegions.Remove(merge); } } System.Diagnostics.Trace.WriteLine("Merging regions :"); foreach (Region r in mergedRegions) System.Diagnostics.Trace.WriteLine("--->"+r.Index.ToString()); pool.Clear(); foreach (Region r in mergedRegions) pool.AddRange(r); this.MakeConstellations(1, pool); nextStartCandidates.Clear(); foreach(Region r in mergedRegions) nextStartCandidates.AddRange(r.adjacentRegions()); nextStartCandidates.RemoveAll((r) => { return mergedRegions.Contains(r); }); nextStartCandidates.RemoveAll((r) => { return !r.isSpawn(); }); nextStartCandidates.RemoveAll((r) => { return !spawnRegions.Contains(r); }); if (nextStartCandidates.Count > 0) start = nextStartCandidates.ElementAt(GalaxyGeneratorPlugin.random.Next(nextStartCandidates.Count)); else if (spawnRegions.Count > 0) start = spawnRegions.ElementAt(GalaxyGeneratorPlugin.random.Next(spawnRegions.Count)); else start = null; } //merge (remaining spawn regions with neutral regions) into result //make (nConstellations - Galaxy.Instance.Constellations.Count) constellations in result System.Diagnostics.Trace.WriteLine("Merging remaining Spawn Regions with Neutral Regions"); System.Diagnostics.Trace.WriteLine("and making remaining Constellations"); pool.Clear(); foreach (Region r in spawnRegions) pool.AddRange(r); foreach (Region r in neutralRegions) pool.AddRange(r); this.MakeConstellations(nConstellations - Galaxy.Instance.Constellations.Count, pool); } } if (Galaxy.Instance.Constellations.Count == 0) { System.Diagnostics.Trace.WriteLine("Failing to associate regions and constellations"); System.Diagnostics.Trace.WriteLine("Creating brutally " + nConstellations.ToString() + " constellations with " + Galaxy.Instance.Stars.Count.ToString()); this.MakeConstellations(nConstellations, Galaxy.Instance.Stars); this.Defects.Add("Unable to correlate regions and constellations"); } this.AggregateIsolatedStars(); } this.Result = true; System.Diagnostics.Trace.WriteLine(this.Name + " - Execute - end"); }
/** * Executes a correction down the line of connected nodes. Only nodes * with the mCorrect flag set to false will be corrected. * * Note: Assumes that the starting node's value is 0. Initiate the * corrective sequence by invoking this method with Dibit.D0 on the * first node. * * @param dibit to use for the left side. */ public void correctTo(Dibit dibit) { if( mCorrect && mConstellation.getLeft() == dibit ) { return; } if( isCurrentConnectionCorrect() ) { mConstellation = Constellation. fromDibits( dibit, mConstellation.getRight() ); mCorrect = true; if( mConnectedNode != null ) { mConnectedNode.correctTo( mConstellation.getRight() ); } } else { Constellation cheapest = mConstellation; int cost = 100; //arbitrary foreach( Dibit d in Dibit.values() ) { Constellation test = Constellation.fromDibits( dibit, d ); int testCost = mConstellation.costTo( test ) + mConnectedNode.costTo( d ); if( testCost < cost ) { cost = testCost; cheapest = test; } } mConstellation = cheapest; mConnectedNode.correctTo( mConstellation.getRight() ); mCorrect = true; } }