/// <summary> /// Set the atom to the most common form of an element /// </summary> /// <param name="protonCount">atomic number of the element to set</param> public void ForceToCommon(int protonCount) { //temporarily remove ingteractivity to force particles bool wasInteractable = interactable; interactable = false; //add or remove neutrons to match atomic number int protonDiff = protonCount - Nucleus.ProtonCount; workbench.NewAutoProton(protonDiff); Nucleus.TrimProtons(-protonDiff); //get the most common stable form of the element Element element = Elements.GetElement(protonCount); if (element != null) { //set the min and max isotope mass Nucleus.MassMax = element.MaxIsotope; Nucleus.MassMin = element.MinIsotope; Isotope common = element.Common; if (common != null) { //add or remove neutrons to match mass int neutronDiff = (common.Mass - protonCount) - Nucleus.NeutronCount; workbench.NewAutoNeutron(neutronDiff); Nucleus.TrimNeutrons(-neutronDiff); } } //add or remove shells to match element period while (shells.Count < Elements.GetShells(protonCount)) { AddShell(); } while (shells.Count > Elements.GetShells(protonCount)) { RemoveShell(); } //add or remove electrons to match charge int electronDiff = protonCount - ElectronCount; workbench.NewAutoElectron(electronDiff); OuterShell.TrimElectrons(-electronDiff); interactable = wasInteractable; //revert interactable state AdjustScale(); }
private void Update() { //get the element Element = Elements.GetElement(Nucleus.ProtonCount); if (Element != null) { //set nucleus shake based on Isotope stability Isotope isotope = Element.GetIsotope(Nucleus.Mass); Nucleus.Shake = isotope != null ? !isotope.Stable : true; //set the min and max isotope mass Nucleus.MassMax = Element.MaxIsotope; Nucleus.MassMin = Element.MinIsotope; //Auto add Neutrons to make valid Isotope if (Nucleus.Mass < Element.MinIsotope) { workbench.NewAutoNeutron(); } //Auto remove Neutrons to make valid Isotope if (Nucleus.Mass > Element.MaxIsotope) { Nucleus.TrimNeutrons(); } } else { Nucleus.MassMax = 0; Nucleus.TrimNeutrons(); } //add or remove shells to match element period while (shells.Count < Elements.GetShells(Nucleus.ProtonCount)) { AddShell(); AdjustScale(); } while (shells.Count > Elements.GetShells(Nucleus.ProtonCount)) { RemoveShell(); AdjustScale(); } }