public YieldSummary GetYieldOfCell(IHexCell cell, ICivilization perspectiveCiv)
        {
            if (cell == null)
            {
                throw new ArgumentNullException("cell");
            }

            YieldSummary retval         = YieldSummary.Empty;
            ICity        cityOwningCell = CellPossessionCanon.GetOwnerOfPossession(cell);

            retval += InherentYieldLogic.GetInherentCellYield(cell, false);

            var nodeAtLocation = NodePositionCanon.GetPossessionsOfOwner(cell).FirstOrDefault();

            var visibleResources = TechCanon.GetResourcesVisibleToCiv(perspectiveCiv);

            var improvementOnCell = ImprovementLocationCanon.GetPossessionsOfOwner(cell).FirstOrDefault();

            var discoveredTechs = TechCanon.GetTechsDiscoveredByCiv(perspectiveCiv);

            bool hasFreshWater = FreshWaterCanon.HasAccessToFreshWater(cell);

            if (cityOwningCell != null)
            {
                var buildingsOnCell = BuildingPossessionCanon.GetPossessionsOfOwner(cityOwningCell)
                                      .Select(building => building.Template);

                retval += BuildingYieldLogic.GetBonusCellYieldFromBuildings(cell, buildingsOnCell);
            }

            if (nodeAtLocation != null)
            {
                retval += NodeYieldLogic.GetYieldFromNode(nodeAtLocation, visibleResources, improvementOnCell);
            }

            if (improvementOnCell != null)
            {
                retval += ImprovementYieldLogic.GetYieldOfImprovement(
                    improvementOnCell, nodeAtLocation, visibleResources, discoveredTechs, hasFreshWater
                    );
            }

            if (perspectiveCiv != null && GoldenAgeCanon.IsCivInGoldenAge(perspectiveCiv) && retval[YieldType.Gold] > 0f)
            {
                retval[YieldType.Gold] += CivConfig.GoldenAgeBonusGoldOnCells;
            }

            return(retval);
        }
        public void ComposeCivilizations(SerializableMapData mapData)
        {
            mapData.Civilizations = new List <SerializableCivilizationData>();

            foreach (var civilization in CivilizationFactory.AllCivilizations)
            {
                var civData = new SerializableCivilizationData()
                {
                    TemplateName     = civilization.Template.Name,
                    GoldStockpile    = civilization.GoldStockpile,
                    CultureStockpile = civilization.CultureStockpile,
                    DiscoveredTechs  = TechCanon.GetTechsDiscoveredByCiv(civilization).Select(tech => tech.Name).ToList(),
                    SocialPolicies   = PolicyComposer.ComposePoliciesFromCiv(civilization),
                };

                if (civilization.TechQueue != null && civilization.TechQueue.Count > 0)
                {
                    civData.TechQueue = civilization.TechQueue.Select(tech => tech.Name).ToList();
                }
                else
                {
                    civData.TechQueue = null;
                }

                var availableTechs = TechCanon.GetTechsAvailableToCiv(civilization);

                if (availableTechs.Count() > 0)
                {
                    foreach (var availableTech in availableTechs)
                    {
                        int progress = TechCanon.GetProgressOnTechByCiv(availableTech, civilization);
                        if (progress != 0)
                        {
                            if (civData.ProgressOnTechs == null)
                            {
                                civData.ProgressOnTechs = new Dictionary <string, int>();
                            }

                            civData.ProgressOnTechs[availableTech.Name] = progress;
                        }
                    }
                }
                else
                {
                    civData.ProgressOnTechs = null;
                }

                var exploredCells = Grid.Cells.Where(cell => ExplorationCanon.IsCellExploredByCiv(cell, civilization));

                civData.ExploredCells = exploredCells.Select(cell => cell.Coordinates).ToList();

                civData.FreeBuildings = FreeBuildingsCanon
                                        .GetFreeBuildingsForCiv(civilization)
                                        .Select(buildingList => buildingList.Select(buildingTemplate => buildingTemplate.name).ToList())
                                        .ToList();

                civData.GoldenAgeTurnsLeft = GoldenAgeCanon.GetTurnsLeftOnGoldenAgeForCiv(civilization);
                civData.GoldenAgeProgress  = GoldenAgeCanon.GetGoldenAgeProgressForCiv(civilization);
                civData.PreviousGoldenAges = GoldenAgeCanon.GetPreviousGoldenAgesForCiv(civilization);

                mapData.Civilizations.Add(civData);
            }

            mapData.CivDiscoveryPairs = CivDiscoveryCanon.GetDiscoveryPairs().Select(
                pair => new Tuple <string, string>(pair.Item1.Template.Name, pair.Item2.Template.Name)
                ).ToList();
        }