Ejemplo n.º 1
0
        public override void OnStateMachineEnter(Animator animator, int stateMachinePathHash)
        {
            Brain.ClearListeners();
            Brain.EnableCameraMovement();

            VisibilityCanon.ResourceVisibilityMode = ResourceVisibilityMode.RevealAll;
            VisibilityCanon.CellVisibilityMode     = CellVisibilityMode.RevealAll;

            ExplorationCanon.ExplorationMode = CellExplorationMode.AllCellsExplored;

            VisibilityResponder.UpdateVisibility = true;

            UnitMapIconManager.BuildIcons();
            UnitMapIconManager.SetActive(true);

            foreach (var element in PlayModeSensitiveElements)
            {
                element.IsActive = false;
            }

            Grid.Build(10, 7);

            var playerCiv    = CivFactory.Create(CivConfig.DefaultTemplate);
            var barbarianCiv = CivFactory.Create(CivConfig.BarbarianTemplate);

            PlayerFactory.CreatePlayer(playerCiv, BrainPile.HumanBrain);
            PlayerFactory.CreatePlayer(barbarianCiv, BrainPile.BarbarianBrain);

            foreach (var chunk in Grid.Chunks)
            {
                chunk.Refresh(Simulation.MapRendering.TerrainRefreshType.All);
            }
        }
Ejemplo n.º 2
0
        private IEnumerator GenerateMap_Perform(IMapTemplate template, IMapGenerationVariables variables)
        {
            MapComposer.ClearRuntime(false);

            while (MapComposer.IsProcessing)
            {
                yield return(new WaitForEndOfFrame());
            }

            Profiler.BeginSample("GenerateMap()");

            CellClimateLogic.Reset(template);

            var oldRandomState = SetRandomState();

            Grid.Build(variables.CellCountX, variables.CellCountZ);

            GeneratePlayers(variables);

            var oceansAndContinents = GenerateOceansAndContinents(template, variables);

            PaintMap(oceansAndContinents, template);

            foreach (var civ in oceansAndContinents.HomelandDataForCiv.Keys)
            {
                var civHomeland = oceansAndContinents.HomelandDataForCiv[civ];

                StartingUnitPlacementLogic.PlaceStartingUnitsInRegion(
                    civHomeland.StartingRegion, civ, template
                    );
            }

            UnityEngine.Random.state = oldRandomState;

            GenerateMapCoroutine = null;

            foreach (var chunk in Grid.Chunks)
            {
                chunk.Refresh(MapRendering.TerrainRefreshType.All);
            }

            Profiler.EndSample();
        }
Ejemplo n.º 3
0
        public void DecomposeCells(SerializableMapData mapData)
        {
            Grid.Build(mapData.CellCountX, mapData.CellCountZ);

            foreach (var cellData in mapData.HexCells)
            {
                var cellToModify = Grid.GetCellAtCoordinates(cellData.Coordinates);

                CellModificationLogic.ChangeTerrainOfCell(cellToModify, cellData.Terrain);
                CellModificationLogic.ChangeShapeOfCell(cellToModify, cellData.Shape);
                CellModificationLogic.ChangeVegetationOfCell(cellToModify, cellData.Vegetation);
                CellModificationLogic.ChangeFeatureOfCell(cellToModify, cellData.Feature);
                CellModificationLogic.ChangeHasRoadsOfCell(cellToModify, cellData.HasRoads);

                cellToModify.SuppressSlot = cellData.SuppressSlot;

                //Converging rivers (where two rivers combine and flow into a third) have
                //order-sensitive creation, since attempting to place both of the inflow
                //rivers before the outflow river has been created is invalid. To account for
                //this, we delay the creation of any invalid rivers (since those represent
                //an inflow being attached to another inflow) until after all other rivers
                //have been placed.
                var delayedRivers = new List <System.Tuple <IHexCell, HexDirection, RiverFlow> >();

                for (int i = 0; i < 6; i++)
                {
                    var edge = (HexDirection)i;

                    if (cellData.HasRiverAtEdge[i] && !RiverCanon.HasRiverAlongEdge(cellToModify, edge))
                    {
                        if (RiverCanon.CanAddRiverToCell(cellToModify, edge, cellData.DirectionOfRiverAtEdge[i]))
                        {
                            RiverCanon.AddRiverToCell(cellToModify, edge, cellData.DirectionOfRiverAtEdge[i]);
                        }
                        else
                        {
                            delayedRivers.Add(new System.Tuple <IHexCell, HexDirection, RiverFlow>(
                                                  cellToModify, edge, cellData.DirectionOfRiverAtEdge[i]
                                                  ));
                        }
                    }
                }

                foreach (var river in delayedRivers)
                {
                    if (RiverCanon.CanAddRiverToCell(river.Item1, river.Item2, river.Item3))
                    {
                        RiverCanon.AddRiverToCell(river.Item1, river.Item2, river.Item3);
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format(
                                                                "Failed to decompose river ({0}, {1}, {2})",
                                                                river.Item1, river.Item2, river.Item3
                                                                ));
                    }
                }

                cellToModify.WorkerSlot.IsOccupied = cellData.IsSlotOccupied;
                cellToModify.WorkerSlot.IsLocked   = cellData.IsSlotLocked;
            }

            foreach (var chunk in Grid.Chunks)
            {
                chunk.Refresh(MapRendering.TerrainRefreshType.All);
            }
        }