protected override void OnOverTile(Vector2Int tileXY)
        {
            base.OnOverTile(tileXY);

            bool canPlace = TileMapData.IsTilePassable(tileXY) && !AreUnitsOnTile(tileXY);

            m_OverlayRenderer.SetOverlayColor(canPlace ? Color.white : Color.red);
        }
Exemple #2
0
        protected override void OnOverTile(Vector2Int tileXY)
        {
            base.OnOverTile(tileXY);

            if (m_SelectedButtonName != "StartLocation")
            {
                bool canPlace = TileMapData.IsTilePassable(tileXY) && !AreUnitsOnTile(tileXY) && !IsWallOnTile(tileXY);
                m_OverlayRenderer.SetTileStatus(Vector2Int.zero, canPlace ? Color.green : Color.red);
            }
        }
Exemple #3
0
        protected override void OnPaintTile(Vector2Int tileXY)
        {
            if (m_SelectedButtonName == "StartLocation")
            {
                // Add game coordinates
                tileXY += Vector2Int.one;

                // Set player start location
                PlayerData   player1    = UserData.current.selectedVariant.players[m_DropdownPlayer.value];
                DataLocation centerView = new DataLocation();
                centerView.x = tileXY.x;
                centerView.y = tileXY.y;
                UserData.current.GetPlayerResourceData(player1).centerView = centerView;
                UserData.current.SetUnsaved();

                m_UnitRenderer.SetStartLocation(m_DropdownPlayer.value, player1);
                return;
            }

            // Check if tile is passable
            if (!TileMapData.IsTilePassable(tileXY))
            {
                return;
            }

            // Check if area is blocked by units or structures
            if (AreUnitsOnTile(tileXY))
            {
                return;
            }

            // Check if area is blocked by wall
            if (IsWallOnTile(tileXY))
            {
                return;
            }

            // Add game coordinates
            tileXY += Vector2Int.one;

            UnitData vehicle = GetVehicleData();

            vehicle.position = new LOCATION(tileXY.x, tileXY.y);

            // Add vehicle to tile
            PlayerData player = UserData.current.selectedVariant.players[m_DropdownPlayer.value];

            UserData.current.GetPlayerResourceData(player).units.Add(vehicle);
            UserData.current.SetUnsaved();

            m_UnitRenderer.AddUnit(player, vehicle);
        }
Exemple #4
0
        protected override void OnOverTile(Vector2Int tileXY)
        {
            base.OnOverTile(tileXY);

            UnitData   structure     = GetStructureData();
            Vector2Int structureSize = StructureData.GetStructureSize(structure.typeID);

            structureSize += new Vector2Int(2, 2);            // Bulldozed area
            Vector2Int minOffset = new Vector2Int(-structureSize.x / 2, -structureSize.y / 2);

            // Set each tile status based on collision within structure area
            for (int x = 0; x < structureSize.x; ++x)
            {
                for (int y = 0; y < structureSize.y; ++y)
                {
                    Vector2Int localTileXY = new Vector2Int(x, y);
                    Vector2Int curTileXY   = tileXY + localTileXY + minOffset;

                    bool isInBulldozedArea = x == 0 || y == 0 || x == structureSize.x - 1 || y == structureSize.y - 1;

                    // Structures can't be placed on impassable terrain, including bulldozed area
                    bool canPlace = TileMapData.IsTilePassable(curTileXY);

                    // Structures can have units in bulldozed area, but not in building area
                    if (canPlace && !isInBulldozedArea)
                    {
                        canPlace = !AreUnitsInArea(new RectInt(curTileXY, Vector2Int.one));
                    }

                    // Structures can have walls in bulldozed area, but not in building area
                    if (canPlace && !isInBulldozedArea)
                    {
                        canPlace = !AreWallsInArea(new RectInt(curTileXY, Vector2Int.one));
                    }

                    Color color = Color.red;
                    if (canPlace)
                    {
                        color = isInBulldozedArea ? Color.yellow : Color.green;
                    }

                    m_OverlayRenderer.SetTileStatus(localTileXY, color);
                }
            }
        }
        protected override void OnPaintTile(Vector2Int tileXY)
        {
            // Check if tile is passable
            if (!TileMapData.IsTilePassable(tileXY))
            {
                return;
            }

            // Check if area is blocked by units or structures
            if (AreUnitsOnTile(tileXY))
            {
                return;
            }

            // Remove wall or tube from tile. We are going to replace it.
            int playerIndex;
            int wallTubeIndex;

            while (GetWallTubeOnTile(tileXY, out playerIndex, out wallTubeIndex))
            {
                UserData.current.GetPlayerResourceData(playerIndex).wallTubes.RemoveAt(wallTubeIndex);
            }

            // Add game coordinates
            tileXY += Vector2Int.one;

            // Create data
            WallTubeData wallTube = new WallTubeData();

            wallTube.typeID   = GetMapIDFromName(m_SelectedButtonName);
            wallTube.position = new LOCATION(tileXY.x, tileXY.y);

            // Add wallTube to tile
            PlayerData player = UserData.current.selectedVariant.players[m_DropdownPlayer.value];

            UserData.current.GetPlayerResourceData(player).wallTubes.Add(wallTube);
            UserData.current.SetUnsaved();

            // Remove game coordinates
            tileXY -= Vector2Int.one;

            m_MapRenderer.RefreshTiles(new RectInt(tileXY.x - 1, tileXY.y - 1, 3, 3));
        }