Example #1
0
        public object Clone()
        {
            SubstanceMixture mixture = new SubstanceMixture(_listImplementation.Count);

            this.AddRange(_listImplementation);
            return(this);
        }
Example #2
0
        public void Concatinate(SubstanceMixture otherMixture)
        {
            _temperature = (_temperature * Volume + otherMixture.Temperature * otherMixture.Volume) /
                           (Volume + otherMixture.Volume);

            foreach (var substance in otherMixture)
            {
                int index = IndexOfSubstance(substance.SubstanceId);

                if (index == -1)
                {
                    _listImplementation.Add(substance);
                    //otherMixture.Remove(Substance);
                }
                else
                {
                    Substance info = _listImplementation[index];

                    /*info.Temperature = (Substance.Temperature * Substance.Volume + info.Temperature * info.Volume) /
                     *  (info.Volume + Substance.Volume);*/

                    info.Volume += substance.Volume;
                    _listImplementation[index] = info;
                }
            }

            _wasModified = true;
        }
Example #3
0
        public void TransferToAnother(ISubstanceContainer otherContainer)
        {
            LogManager.RuntimeLogger.Log($"{ContainingTileObject?.VisibleName} transfers substance mixture into other container. New contents: " + _mixture);

            float amount = Math.Min(_transferAmount, _mixture.Volume);

            if (Math.Abs(amount) < 0.0001f)
            {
                LogManager.RuntimeLogger.Log("Nothing to transfer!");
            }
            else
            {
                LogManager.RuntimeLogger.Log("Amount: " + amount);
                SubstanceMixture subtractedMixture = _mixture.SubtractVolume(amount);

                otherContainer.TransferInto(subtractedMixture);

                _mixture.Concatinate(subtractedMixture);
            }
        }
Example #4
0
        public void TransferInto(SubstanceMixture incomingMixture)
        {
            float remainingVolume = RemainingVolume;

            SubstanceMixture concatinationMixture;

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

            _mixture.Concatinate(concatinationMixture);

            LogManager.RuntimeLogger.Log($"{ContainingTileObject?.VisibleName} received substance mixture. New contents: " + _mixture);
        }
Example #5
0
        public SubstanceMixture SubtractPart(float part)
        {
            if (part > 1 || part <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(part), "Must be inside (0, 1]");
            }


            SubstanceMixture mixture = new SubstanceMixture(_listImplementation.Count);

            for (int i = 0; i < _listImplementation.Count; i++)
            {
                Substance info       = _listImplementation[i];
                Substance subtracted = info;
                subtracted.Volume *= part;
                info.Volume       -= subtracted.Volume;
                this.Add(subtracted);
                _listImplementation[i] = info;
            }

            return(this);
        }
Example #6
0
        private void DoReaction(Reaction reaction, int[] reagentsIndexes, float factor)
        {
            for (int i = 0; i < reagentsIndexes.Length; i++)
            {
                int reagentIndex = reagentsIndexes[i];
                if (reagentIndex < 0 || reagentIndex >= this.Count || this.Count == 0)
                {
                    return;
                }
                Substance substanceInfo  = this[reagentIndex];
                float     reactionVolume = factor * reaction.Reagents[i].Mole;
                substanceInfo.Volume -= reactionVolume;

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

            SubstanceMixture additions = new SubstanceMixture(0, this.Temperature + reaction.ThermalFactor * factor);

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

            this.Concatinate(additions);
        }
Example #7
0
        public SubstanceMixture SubtractVolume(float volume)
        {
            if (volume > Volume)
            {
                throw new ArgumentOutOfRangeException(nameof(volume), "Must be inside (0, Volume of this instance]. Current volume: " + Volume);
            }

            SubstanceMixture mixture = new SubstanceMixture(_listImplementation.Count);

            float volumeTmp = Volume;

            for (int i = 0; i < _listImplementation.Count; i++)
            {
                Substance info       = _listImplementation[i];
                Substance subtracted = info;
                subtracted.Volume      = volume * info.Volume / volumeTmp;
                info.Volume           -= subtracted.Volume;
                _listImplementation[i] = info;

                this.Add(subtracted);
            }

            return(this);
        }