Exemplo n.º 1
0
    public void InitializeGrid()
    {
        (int gridLayersIn, int gridSlicesIn) = grid.GetGridSize();
        nodeGrid = new PathNodeHolder <GridCell> [gridLayersIn, gridSlicesIn];

        gridLayers = gridLayersIn;
        gridSlices = gridSlicesIn;

        //Set up pathfinding nodes
        foreach (GridCell cell in grid.gridCells)
        {
            PathNodeHolder <GridCell> holder = new PathNodeHolder <GridCell>();
            holder.node  = cell;
            holder.gCost = int.MaxValue;
            holder.hCost = cell.hCost;
            holder.CalculateFCost();
            holder.previousNodeHolder = null;
            holder.SetNeighbors(cell.GetNeighbors());
            holder.id = holder.node.GetInstanceID();
            nodeGrid[cell.layer, cell.slice] = holder;
        }

        //Set up pathfinding nodes
        foreach (PathNodeHolder <GridCell> node in nodeGrid)
        {
            List <PathNodeHolder <GridCell> > neighbors = new List <PathNodeHolder <GridCell> >();

            int layer = node.node.layer;
            int slice = node.node.slice;

            if (layer - 1 >= 0)
            {
                neighbors.Add(nodeGrid[layer - 1, slice]);
            }
            if (layer + 1 < gridLayersIn)
            {
                neighbors.Add(nodeGrid[layer + 1, slice]);
            }
            if (slice - 1 >= 0)
            {
                neighbors.Add(nodeGrid[layer, slice - 1]);
            }
            if (slice - 1 == -1)
            {
                neighbors.Add(nodeGrid[layer, gridSlicesIn - 1]);
            }
            if (slice + 1 < gridSlicesIn)
            {
                neighbors.Add(nodeGrid[layer, slice + 1]);
            }
            if (slice + 1 == gridSlicesIn)
            {
                neighbors.Add(nodeGrid[layer, 0]);
            }

            node.SetNeighbors(neighbors);
        }
    }
Exemplo n.º 2
0
    private (GridCell north, GridCell south, GridCell east, GridCell west) GetLandingGridCells(CircularGrid grid)
    {
        (int tempLay, int tempSlice) = grid.GetGridSize();
        int      slices     = tempSlice - 1;
        int      outerLayer = tempLay - 2;
        GridCell eastCell   = grid.GetGridCell(outerLayer, 0);
        GridCell northCell  = grid.GetGridCell(outerLayer, Mathf.CeilToInt(slices / 4) * 1);
        GridCell westCell   = grid.GetGridCell(outerLayer, Mathf.CeilToInt(slices / 4) * 2);
        GridCell southCell  = grid.GetGridCell(outerLayer, Mathf.CeilToInt(slices / 4) * 3);

        return(northCell, southCell, eastCell, westCell);
    }
Exemplo n.º 3
0
    public void PlaceUnits()
    {
        // parentCell = GameStateManager.Instance.solarSystemGrid.GetGridCell(6, 19);
        // GameStateManager.Instance.Factions[0].CreateUnit(parentCell, this.unitNames[1]);

        List <Planet> planetsContainingAFaction = new List <Planet>();

        //We'll place each faction on its own planet
        foreach (Faction faction in GameStateManager.Instance.Factions)
        {
            //Initialize a planet
            Planet placementPlanet = null;
            //Select a random planet, and continue selecting random planets until we find one that doesn't house a faction
            do
            {
                placementPlanet = PlanetManager.Instance.planets[Random.Range(0, PlanetManager.Instance.planets.Count)];
            }while (planetsContainingAFaction.Contains(placementPlanet));

            //Place the faction's main base onto a random cell in the planet grid
            CircularGrid planetGrid  = placementPlanet.grid;
            int          randomLayer = Random.Range(0, planetGrid.GetGridSize().layers - 1);
            int          randomSlice = Random.Range(0, planetGrid.GetGridSize().slices);
            GridCell     parentCell  = placementPlanet.grid.GetGridCell(randomLayer, randomSlice);

            bool isLocalPlayerFaction = faction.Identity.isLocalPlayer;

            faction.CreateUnit(parentCell, "Main Base");

            //If this is the player faction, put their planet in view just to be nice
            if (isLocalPlayerFaction)
            {
                GameStateManager.Instance.GridInView = planetGrid;
            }
            planetsContainingAFaction.Add(placementPlanet);
        }
    }