public ICivilization Create(ICivilizationTemplate template, IEnumerable <ITechDefinition> startingTechs)
        {
            if (template == null)
            {
                throw new ArgumentNullException("template");
            }

            var newCivilization = Container.InstantiateComponentOnNewGameObject <Civilization>();

            newCivilization.Template = template;

            if (CivContainer != null)
            {
                newCivilization.transform.SetParent(CivContainer, false);
            }

            allCivilizations.Add(newCivilization);

            foreach (var tech in startingTechs)
            {
                TechCanon.SetTechAsDiscoveredForCiv(tech, newCivilization);
            }

            Signals.NewCivilizationCreated.OnNext(newCivilization);

            return(newCivilization);
        }
        private void OnTechRecordClicked_SetDiscoveredTechs(TechnologyRecord techRecord)
        {
            var techClicked = techRecord.TechToDisplay;

            if (TechCanon.IsTechDiscoveredByCiv(techClicked, ObjectToDisplay))
            {
                foreach (var postrequisiteTech in TechCanon.GetDiscoveredPostrequisiteTechs(techClicked, ObjectToDisplay))
                {
                    TechCanon.SetTechAsUndiscoveredForCiv(postrequisiteTech, ObjectToDisplay);
                }

                TechCanon.SetTechAsUndiscoveredForCiv(techClicked, ObjectToDisplay);
            }
            else
            {
                foreach (var tech in TechCanon.GetPrerequisiteChainToResearchTech(techClicked, ObjectToDisplay))
                {
                    TechCanon.SetTechAsDiscoveredForCiv(tech, ObjectToDisplay);
                }
            }

            Refresh();
        }
        private void DecomposeTechs(SerializableCivilizationData civData, ICivilization newCiv)
        {
            if (civData.TechQueue != null)
            {
                for (int i = 0; i < civData.TechQueue.Count; i++)
                {
                    var techName = civData.TechQueue[i];

                    var techOfName = AvailableTechs.Where(tech => tech.Name.Equals(techName)).FirstOrDefault();
                    if (techOfName == null)
                    {
                        throw new InvalidOperationException(string.Format("CivData.TechQueue had invalid tech name {0} in it", techName));
                    }
                    newCiv.TechQueue.Enqueue(techOfName);
                }
            }

            if (civData.DiscoveredTechs != null)
            {
                foreach (var discoveredTechName in civData.DiscoveredTechs)
                {
                    var techOfName = AvailableTechs.Where(tech => tech.Name.Equals(discoveredTechName)).FirstOrDefault();
                    if (techOfName == null)
                    {
                        throw new InvalidOperationException(
                                  string.Format("CivData.DiscoveredTechs had invalid tech name {0} in it", discoveredTechName)
                                  );
                    }

                    TechCanon.SetTechAsDiscoveredForCiv(techOfName, newCiv);
                }
            }

            if (civData.ProgressOnTechs != null)
            {
                foreach (var techInProgressName in civData.ProgressOnTechs.Keys)
                {
                    var techOfName = AvailableTechs.Where(tech => tech.Name.Equals(techInProgressName)).FirstOrDefault();
                    if (techOfName == null)
                    {
                        throw new InvalidOperationException(
                                  string.Format("CivData.ProgressOnTechs had invalid tech name {0} in it", techInProgressName)
                                  );
                    }

                    TechCanon.SetProgressOnTechByCiv(techOfName, newCiv, civData.ProgressOnTechs[techInProgressName]);
                }
            }
        }
        public void PerformResearch()
        {
            if (TechQueue.Count > 0)
            {
                var activeTech = TechQueue.Peek();

                int techProgress = TechCanon.GetProgressOnTechByCiv(activeTech, this);
                techProgress += LastScienceYield;

                if (techProgress >= activeTech.Cost && TechCanon.IsTechAvailableToCiv(activeTech, this))
                {
                    TechCanon.SetTechAsDiscoveredForCiv(activeTech, this);
                    TechQueue.Dequeue();
                }
                else
                {
                    TechCanon.SetProgressOnTechByCiv(activeTech, this, techProgress);
                }
            }
        }