Ejemplo n.º 1
0
        public void TransferInto(SubstanceMixture incomingMixture)
        {
            float remainingVolume = GetRemainingVolume();

            SubstanceMixture concatinationMixture;

            if (remainingVolume >= incomingMixture.Volume)
            {
                concatinationMixture = incomingMixture.Clone() as SubstanceMixture;
                incomingMixture.Clear();
            }
            else
            {
                concatinationMixture = incomingMixture.SubtractVolume(remainingVolume);
            }

            _mixture.Concatinate(concatinationMixture);

            Debug.Log(gameObject.name + ": New contents: " + _mixture);
        }
Ejemplo n.º 2
0
        private static void DoReaction(SubstanceMixture mixture, Reaction reaction, int[] reagentsIndexes, float factor)
        {
            for (int i = 0; i < reagentsIndexes.Length; i++)
            {
                int reagentIndex = reagentsIndexes[i];
                if (reagentIndex < 0 || reagentIndex >= mixture.Count || mixture.Count == 0)
                {
                    return;
                }
                SubstanceInfo substanceInfo  = mixture[reagentIndex];
                float         reactionVolume = factor * reaction.Reagents[i].Mole;
                substanceInfo.Volume -= reactionVolume;

                if (substanceInfo.Volume > 0)
                {
                    mixture[reagentIndex] = substanceInfo;
                }
                else
                {
                    mixture.RemoveAt(reagentIndex);
                }
            }

            SubstanceMixture additions = new SubstanceMixture(0, mixture.Temperature + reaction.TermalFactor * factor);

            for (int i = 0; i < reaction.Results.Length; i++)
            {
                int id = ChemistryController.Current.GetSubstance(reaction.Results[i].SubstanceName).Id;
                if (id != -1)
                {
                    additions.Add(new SubstanceInfo(id, factor * reaction.Results[i].Mole));
                }
            }

            mixture.Concatinate(additions);
        }