コード例 #1
0
    void ModulesTest()
    {
        int v = 5;
        int h = 4;

        listAgents = new Agent[v + h];

        for (int i = 0; i < v; i++)
        {
            Cell cell = grid.GetCell(new Vector3Int(0, i, 0));
            cell.Alive = true;

            Agent agent = new Agent(agentPrefab, Material, physicsMaterial, cell.Center, i);
            cell.agent = agent;

            listAgents[i]      = agent;
            listAgents[i].Cell = cell;
        }

        for (int i = 0; i < h; i++)
        {
            Cell cell = grid.GetCell(new Vector3Int(i + 1, v - 1, 0));
            cell.Alive = true;

            Agent agent = new Agent(agentPrefab, Material, physicsMaterial, cell.Center, v + i);
            cell.agent = agent;

            listAgents[v + i]      = agent;
            listAgents[v + i].Cell = cell;
        }
    }
コード例 #2
0
ファイル: Player.cs プロジェクト: asandberg/AInversus
 // Use this for initialization
 void Start()
 {
     homeState    = grid.GetCell((int)location.x, (int)location.y);
     initLocation = location;
     SetLocation(location);
     bullets = new List <Bullet>();
 }
コード例 #3
0
    public void Init(CellGrid.Cell cell, CellGrid cellGrid)
    {
        _listOfFreeConnections = new List <TileConnector>();
        for (int i = 0; i < connections.Length; ++i)
        {
            connections[i].ownerTile = this;

            if (connections[i].IsConnected)
            {
                continue;
            }

            if (connections[i].direction == TileConnector.DIRECTION.TOP)
            {
                if (cell.row == cellGrid.TotalRows - 1 || cellGrid.GetCell(cell.row + 1, cell.col).IsOccupied())
                {
                    connections[i].SetToInvalid();
                }
            }
            else if (connections[i].direction == TileConnector.DIRECTION.BOT)
            {
                if (cell.row == 0 || cellGrid.GetCell(cell.row - 1, cell.col).IsOccupied())
                {
                    connections[i].SetToInvalid();
                }
            }
            else if (connections[i].direction == TileConnector.DIRECTION.LEFT)
            {
                if (cell.col == 0 || cellGrid.GetCell(cell.row, cell.col - 1).IsOccupied())
                {
                    connections[i].SetToInvalid();
                }
            }
            else if (connections[i].direction == TileConnector.DIRECTION.RIGHT)
            {
                if (cell.col == cellGrid.TotalCols - 1 || cellGrid.GetCell(cell.row, cell.col + 1).IsOccupied())
                {
                    connections[i].SetToInvalid();
                }
            }

            if (!connections[i].IsInvalid)
            {
                _listOfFreeConnections.Add(connections[i]);
            }
        }

        cell.tile = this;
        _cell     = cell;
    }
コード例 #4
0
        private void DrawCellGrid(SpriteBatch spriteBatch, CellGrid cellGrid, Camera camera)
        {
            var fromRow = camera.CameraTopLeftHex.Y - 1;
            var toRow   = camera.CameraBottomRightHex.Y + 1;

            var fromColumn = camera.CameraTopLeftHex.X - 1;
            var toColumn   = camera.CameraBottomRightHex.X + 1;

            for (var r = fromRow; r <= toRow; r++)
            {
                for (var q = fromColumn; q <= toColumn; q++)
                {
                    var cell = cellGrid.GetCell(q, r);

                    if (cell.SeenState == SeenState.NeverSeen)
                    {
                        DrawCell(spriteBatch, cell, Color.White);
                    }
                    else if (cell.IsSeenByPlayer(WorldView.Settlements, WorldView.Stacks))
                    {
                        DrawCell(spriteBatch, cell, Color.White);
                    }
                    else
                    {
                        DrawCell(spriteBatch, cell, Color.DarkGray);
                    }

                    //DrawHexBorder(spriteBatch, cell);
                    DrawBorders(spriteBatch, cell);
                }
            }
        }
コード例 #5
0
    // PlaceAgentsInGivenGeometry: Places the agents in a given list of points that forms a 3D shape (only for points inside the lattice)
    public Agent[] PlaceAgentsInGivenGeometry(IEnumerable <Vector3> listPositions)
    {
        for (int i = 0; i < NumberOfAgents; i++)    // CHECK EXCEPTION: NumAgents != listPositions.Count()
        {
            Vector3Int cellLocation = _grid.GetCellLocation(listPositions.ElementAt(i));

            Cell currentCell = _grid.GetCell(cellLocation);
            currentCell.Alive     = true;
            currentCell.Occupancy = CellOccupancy.Occupied;

            Agent newAgent = new Agent(agent, material, physicsMaterial, currentCell.Center, i);
            currentCell.agent = newAgent;
            newAgent.Cell     = currentCell;

            listAgents[i] = newAgent;
        }
        return(listAgents);
    }
コード例 #6
0
 void HandleInput()
 {
     if (isLevelEditorEnabled)
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             EditCell(cellGrid.GetCell(hit.point));
         }
     }
 }
コード例 #7
0
ファイル: MinimapHandler.cs プロジェクト: gmoller/Phoenix
        internal static Texture2D Create(CellGrid cellGrid)
        {
            var gameConfigCache = CallContext <GameConfigCache> .GetData("GameConfigCache");

            var context = CallContext <GlobalContextPresentation> .GetData("GlobalContextPresentation");

            var graphicsDevice = context.GraphicsDevice;

            var scalingFactorX = 7;
            var scalingFactorY = 6;
            var width          = cellGrid.NumberOfColumns;
            var height         = cellGrid.NumberOfRows;
            var scaledWidth    = (width * scalingFactorX) + 4;  // Math.Ceiling(scalingFactorX * Constants.ONE_HALF)
            var scaledHeight   = (height * scalingFactorY) + 4; // scalingFactorY * Constants.ONE_HALF

            var colors = new Color[scaledWidth, scaledHeight];

            for (var row1 = 0; row1 < height; row1++)
            {
                var evenLine = row1.IsEven();
                for (var column1 = 0; column1 < width; column1++)
                {
                    var cell      = cellGrid.GetCell(column1, row1);
                    var terrainId = cell.TerrainId;
                    var terrain   = gameConfigCache.GetTerrainConfigById(terrainId);
                    var color     = terrain.MinimapColor.ToColor();

                    var hexColors = GetHexColors(color, Color.DarkSlateGray, cell.SeenState);

                    for (var row2 = 0; row2 < 8; row2++)
                    {
                        for (var column2 = 0; column2 < 7; column2++)
                        {
                            var col = (column1 * 7) + column2 + (evenLine ? 0 : 3);
                            var row = (row1 * 6) + row2;

                            if (colors[col, row] == Color.Transparent)
                            {
                                colors[col, row] = hexColors[column2, row2];
                            }
                        }
                    }
                }
            }

            var colors1D = colors.To1DArray();
            var minimap  = new Texture2D(graphicsDevice, scaledWidth, scaledHeight, false, SurfaceFormat.Color);

            minimap.SetData(colors1D);

            return(minimap);
        }
コード例 #8
0
        private (bool potentialMovement, PointI hexToMoveTo) CheckForPotentialUnitMovement(Stack stack, CellGrid cellGrid, Point mouseLocation, Camera camera)
        {
            var hexToMoveTo  = camera.ScreenPixelToWorldHex(mouseLocation);
            var cellToMoveTo = cellGrid.GetCell(hexToMoveTo.Col, hexToMoveTo.Row);

            if (cellToMoveTo.SeenState == SeenState.NeverSeen)
            {
                return(false, new PointI(0, 0));
            }
            var costToMoveIntoResult = PhoenixGameLibrary.Helpers.MovementCosts.GetCostToMoveInto(cellToMoveTo, stack.MovementTypes, stack.MovementPoints);

            return(costToMoveIntoResult.CanMoveInto, new PointI(hexToMoveTo.Col, hexToMoveTo.Row));
        }
コード例 #9
0
    public void UpdateBasedOnGrd(CellGrid cellGrid)
    {
        CellGrid.Cell myCell = ownerTile.Cell;
        int           r      = myCell.row;
        int           c      = myCell.col;

        if (direction == DIRECTION.TOP)
        {
            ConnectIfPossible(cellGrid.GetCell(r + 1, c));
        }
        else if (direction == DIRECTION.BOT)
        {
            ConnectIfPossible(cellGrid.GetCell(r - 1, c));
        }
        else if (direction == DIRECTION.LEFT)
        {
            ConnectIfPossible(cellGrid.GetCell(r, c - 1));
        }
        else if (direction == DIRECTION.RIGHT)
        {
            ConnectIfPossible(cellGrid.GetCell(r, c + 1));
        }
    }
コード例 #10
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0) && !IsPointerOverUIObject())
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             Cell hitCell = cellGrid.GetCell(hit.point);
             //Debug.Log(string.Format("Clicked: {0}", hitCell.name));
             EventManager.TriggerEvent(CustomEventType.ClickedCell, hitCell);
         }
     }
 }
コード例 #11
0
    private void LoadMode(int mode)
    {
        if (mode == 0)
        {
            simulationMode = SimulationMode.Pathfinding;

            isAcceptingPathfindingInput = true;
            pathfinder.SelectHeuristicWeight(0);
            pathfindingAgent.gameObject.SetActive(true);
            pathfindingAgent.Initialize_PathfindingAgent(cellGrid, pathfinder);
            pathfindingAgent.PlaceOnGrid(cellGrid.GetCell(12, 12));
            pathfindingAgent.movementMode = MovementMode.Pathing;
            agentManager.agents.Add(pathfindingAgent);

            pathfinderButtonObject.SetActive(true);
            TogglePanel_Pathfinder(true);
        }
        else if (mode == 1)
        {
            simulationMode           = SimulationMode.Steering;
            isAcceptingSteeringInput = true;
            boidManager.gameObject.SetActive(true);
            boidManager.Initialize(cellGrid);
            //boidManager.ToggleBoids();
            boidManager.CreateBoids(15);
            boidManager.ToggleVisualization_Steering(true);
            boidManager.ToggleVisualization_Velocity(true);
            boidManager.ChangeMode_SeekAndSeperation();

            boidManagerButtonObject.SetActive(true);
            TogglePanel_BoidManager(true);
        }
        else if (mode == 2)
        {
            simulationMode = SimulationMode.Ecosystem;

            biome.SpawnPlants(100);
            biome.isSpawningNewPlants = true;
            biome.AdjustPlantSpawnRate(0f);

            agentManager.CreateAgents(5);
            agentManager.isSelectionEnabled = true;

            ecosystemManagerButtonObject.SetActive(true);
            TogglePanel_EcosystemManager(true);
            influenceMapManager.TogglePopulationMapOptions(false);
            selectedAgentButtonObject.SetActive(true);
        }
    }
コード例 #12
0
    public void Generate()
    {
        _prevRandomState = Random.state;

        _cellGrid = new CellGrid(transform.position, gridRows, gridCols, gridSize);

        Reset();

        // Start Tile
        CreateTile(_cellGrid.GetCell(startRow, startCol), TILE_TYPE.START);

        // Connection Tiles
        if (autoGeneration)
        {
            while (GenerateNextTile())
            {
                // Keep generating as long as the conditions are valid
            }
        }

        // Fill Connection Gaps
        if (autoGenerationFillGaps)
        {
            while (CloseFreeConnection())
            {
                // Close all free connections if they still exist
            }
        }

        // End Tiles
        if (autoGenerationFillEndTiles)
        {
            // Sort by furthest distance from start tile
            _listOfFreeConnections.Sort(DistanceFromStartTile);
            GenerateEndTile();
        }

        // Dead Ends
        if (autoGenerationFillDeadEnds)
        {
            while (CloseDeadEnds())
            {
                // Close all free connections if they still exist
            }
        }

        // Assign distance from nodes
    }
コード例 #13
0
        private static void DrawTileInfo(SpriteBatch spriteBatch, SpriteFont font, float x, float y, CellGrid cellGrid, HexOffsetCoordinates hexPoint)
        {
            var cell = cellGrid.GetCell(hexPoint);

            if (cell.SeenState == SeenState.NeverSeen)
            {
                return;
            }

            var terrain               = GetTerrain(cell.TerrainId);
            var terrainTypeText       = $"{terrain.Name} - {terrain.FoodOutput} food";
            var maximumPopulationText = GetMaximumPopulationText(cell.TerrainId, cellGrid, hexPoint);

            spriteBatch.DrawString(font, terrainTypeText, new Vector2(x, y), Color.White);
            spriteBatch.DrawString(font, maximumPopulationText, new Vector2(x, y + 15.0f), Color.White);
        }
コード例 #14
0
    ////////////////////////////   MOVEMENTS  ////////////////////////////

    // INDIVIDUAL MOVE
    // ModuleRotation: Rotate a module around a pivot module
    private void ModuleRotation(Agent agent, Agent pivot, Vector3 rotationAxis, float angle)
    {
        Cell currentCell = agent.Cell;

        agent.Obj.transform.RotateAround(pivot.Obj.transform.position, rotationAxis, angle);
        pivot.Obj.transform.RotateAround(pivot.Obj.transform.position, rotationAxis, angle);

        Cell newCell = grid.GetCell(grid.GetCellLocation(agent.Obj.transform.position));

        agent.Cell = newCell;

        currentCell.Alive = false;
        currentCell.agent = null;

        newCell.Alive = true;
        newCell.agent = agent;
    }
コード例 #15
0
    public void UpdateAgent_Movement()
    {
        if (isDead)
        {
            return;
        }

        if (movementMode == MovementMode.Pathing)
        {
            movementController.FixedUpdate_MovementController();
        }
        else if (movementMode == MovementMode.Steering)
        {
            simpleVehicleModel.UpdateSteering();
        }

        Cell = CellGrid.GetCell(transform.position);
    }
コード例 #16
0
    internal List <Cell> GenerateGoalShape(List <Vector3Int> startingPoints, int nModules)
    {
        int tries = 100;    ///// tries -> loop failsafe
        int count = 0;

        Cell[]      cells     = new Cell[startingPoints.Count];
        List <Cell> goalCells = new List <Cell>();

        // Place starting Cells
        foreach (Vector3Int point in startingPoints)
        {
            Cell currentCell = grid.GetCell(point);
            //currentCell.GoalCell = true;
            cells[count] = currentCell;
            goalCells.Add(currentCell);
            count++;
        }

        //Place remaining cells
        while (count < nModules && tries-- > 0)
        {
            for (int i = 0; i < cells.Length; i++)
            {
                var faceNeighbours = cells[i].GetFaceNeighbours().Where(n => !goalCells.Any(cell => cell.Location == n.Location)).ToArray();
                int nNeighbours    = faceNeighbours.Length;

                if (nNeighbours != 0)
                {
                    Cell randomNeighbour = faceNeighbours[UnityEngine.Random.Range(0, nNeighbours)];
                    //randomNeighbour.GoalCell = true;
                    cells[i] = randomNeighbour;
                    goalCells.Add(randomNeighbour);
                    count++;
                }
            }
        }

        return(goalCells);
    }
コード例 #17
0
    Tile FindConnectionTile(CellGrid.Cell cell)
    {
        // Find total neighbors on this cell
        int r = cell.row;
        int c = cell.col;
        // Top
        bool isTopNeeded  = false;
        bool isTopBlocked = false;

        if (r + 1 < gridRows - 1)
        {
            CellGrid.Cell topCell = _cellGrid.GetCell(r + 1, c);
            if (topCell.IsOccupied())
            {
                if (topCell.tile.GetOppositeConnector(TileConnector.DIRECTION.TOP) != null)
                {
                    isTopNeeded = true;
                }
                else
                {
                    isTopBlocked = true;
                }
            }
        }
        else
        {
            isTopBlocked = true;
        }
        // Bot
        bool isBotNeeded  = false;
        bool isBotBlocked = false;

        if (r > 0)
        {
            CellGrid.Cell botCell = _cellGrid.GetCell(r - 1, c);
            if (botCell.IsOccupied())
            {
                if (botCell.tile.GetOppositeConnector(TileConnector.DIRECTION.BOT) != null)
                {
                    isBotNeeded = true;
                }
                else
                {
                    isBotBlocked = true;
                }
            }
        }
        else
        {
            isBotBlocked = true;
        }
        // Right
        bool isRightNeeded  = false;
        bool isRightBlocked = false;

        if (c + 1 < gridCols - 1)
        {
            CellGrid.Cell rightCell = _cellGrid.GetCell(r, c + 1);
            if (rightCell.IsOccupied())
            {
                if (rightCell.tile.GetOppositeConnector(TileConnector.DIRECTION.RIGHT) != null)
                {
                    isRightNeeded = true;
                }
                else
                {
                    isRightBlocked = true;
                }
            }
        }
        else
        {
            isRightBlocked = true;
        }
        // Left
        bool isLeftNeeded  = false;
        bool isLeftBlocked = false;

        if (c > 0)
        {
            CellGrid.Cell leftCell = _cellGrid.GetCell(r, c - 1);
            if (leftCell.IsOccupied())
            {
                if (leftCell.tile.GetOppositeConnector(TileConnector.DIRECTION.LEFT) != null)
                {
                    isLeftNeeded = true;
                }
                else
                {
                    isLeftBlocked = true;
                }
            }
        }
        else
        {
            isLeftBlocked = true;
        }

        for (int i = 0; i < _totalTilesInBaseTileSet; ++i)
        {
            Tile baseTile       = _baseTileSet[i];
            int  numConnections = baseTile.connections.Length;

            if (numConnections == 1)
            {
                continue;
            }

            bool isTopValid   = !isTopNeeded;
            bool isBotValid   = !isBotNeeded;
            bool isRightValid = !isRightNeeded;
            bool isLeftValid  = !isLeftNeeded;
            for (int j = 0; j < numConnections; ++j)
            {
                if (baseTile.connections[j].direction == TileConnector.DIRECTION.TOP)
                {
                    if (isTopNeeded)
                    {
                        isTopValid = true;
                    }
                    else if (isTopBlocked)
                    {
                        isTopValid = false;
                    }
                }
                else if (baseTile.connections[j].direction == TileConnector.DIRECTION.BOT)
                {
                    if (isBotNeeded)
                    {
                        isBotValid = true;
                    }
                    else if (isBotBlocked)
                    {
                        isBotValid = false;
                    }
                }
                else if (baseTile.connections[j].direction == TileConnector.DIRECTION.RIGHT)
                {
                    if (isRightNeeded)
                    {
                        isRightValid = true;
                    }
                    else if (isRightBlocked)
                    {
                        isRightValid = false;
                    }
                }
                else if (baseTile.connections[j].direction == TileConnector.DIRECTION.LEFT)
                {
                    if (isLeftNeeded)
                    {
                        isLeftValid = true;
                    }
                    else if (isLeftBlocked)
                    {
                        isLeftValid = false;
                    }
                }
            }

            if (isTopValid && isBotValid && isRightValid && isLeftValid)
            {
                return(baseTile);
            }
        }

        Debug.Log("Error: Unable to find a connection tile so skipping");
        return(null);
    }
コード例 #18
0
    public void PathToCell(Vector3 position)
    {
        Node possibleGoalNode = cellGrid.GetCell(position).node;

        PathToNode(possibleGoalNode);
    }
コード例 #19
0
    /// <summary> Will return false if unable to place on grid. </summary>
    public bool PlaceOnGrid(int column, int row)
    {
        Cell possibleCell = CellGrid.GetCell(column, row);

        return(PlaceOnGrid(possibleCell));
    }
コード例 #20
0
 public int GetRegionID(Vector3 position)
 {
     return(cellGrid.GetCell(position).regionID);
 }
コード例 #21
0
ファイル: Helpers.cs プロジェクト: joesycalik/LD42
 //Return the Cell under an input position
 public static Cell GetCellUnderCursor(CellGrid cellGrid)
 {
     return cellGrid.GetCell(Camera.main.ScreenPointToRay(Input.mousePosition));
 } //End GetCellUnderCursor()
コード例 #22
0
ファイル: Helpers.cs プロジェクト: joesycalik/LD42
    } //End GetCellUnderCursor()

    //Return the Cell under an input position
    public static Cell GetCellUnderPosition(CellGrid cellGrid, Vector3 position)
    {
        return cellGrid.GetCell(position);
    } //End GetCellUnderCursor()