Example #1
0
        public void ApplyCell(MapCellData cell)
        {
            if (cell.IsFirst)
            {
                this.CellList.Clear();
            }
            this.CellList.Add(cell);

            this.RequestUpdate();
        }
Example #2
0
        public void AddTerrainCell(Texture2D texture, MapCellData pData)
        {
            GameObject     obj  = GameGOW.Get().ResourceMgr.GetRes("Prefab/MapCell");
            SpriteRenderer spr  = obj.GetComponent <SpriteRenderer>();
            Rect           rect = new Rect(0, 0, texture.width, texture.height);
            Sprite         sp   = Sprite.Create(texture, rect, new Vector2(0, 0));

            spr.sprite                  = sp;
            obj.transform.parent        = m_pTerrainLayer;
            obj.transform.localPosition = new Vector3(pData.pos_x, pData.pos_y, m_pBackGroundLayer.position.z - m_pTerrainLayer.childCount * 0.01f);
        }
Example #3
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="data">Map cell data loaded from a save</param>
 /// <param name="province">The province including the map cell</param>
 public MapCell(MapCellData data, Province province)
 {
     _data     = data;
     _province = province;
     if (_data.provinceId != province.GetId())
     {
         Debug.Log("Bad province data for map cell at " + _data.x + ", " + _data.y + ": " + _data.provinceId + " is changed to " + province.GetId());
         _data.provinceId = province.GetId();
     }
     // assume that all neighbors belong to a different province or provinces
     _provinceBordersIndex = 63;
 }
Example #4
0
    //===================== map function =================================
    public MapCellData GetMapCellData(MapCoordinates pos)
    {
        if (!IsMapCoordValid(pos))
        {
            DebugUtil.Error("Get Wrong Cell Data, pos is ", pos);
        }
        int key = pos.Z * this.mapGrid.width + pos.X;

        if (mapDatas[key] == null)
        {
            mapDatas[key] = new MapCellData();
        }
        return(mapDatas[key]);
    }
    static MapCellData DeserializeMapCell(byte[] bytes)
    {
        byte[][]    data_array = ArrayConcatenation.UnmergeArrays(bytes);
        MapCellData cell       = new MapCellData();

        cell.has_silo = BitConverter.ToBoolean(data_array[0], 0);
        cell.is_nuked = BitConverter.ToBoolean(data_array[1], 0);
        cell.owner_id = BitConverter.ToInt32(data_array[2], 0);

        Debug.Log(data_array.Length);
        Debug.Log(data_array[4].Length);
        byte[][]       land_bytes          = ArrayConcatenation.UnmergeArrays(data_array[4]);
        List <Vector2> deserialized_coords = new List <Vector2>();

        return(cell);
    }
Example #6
0
    public void TransitionToCover(Vector3 mapPos)
    {
        StopMoving();
        MapCellData mapData = mapControl.GetData(mapPos);

        transitionPos[0] = transform.position;
        transitionPos[1] = mapData.position;
        transitionRot[0] = transform.rotation;
        transitionRot[1] = mapData.rotation;
        IsTransitioning  = true;

        string coverType = mapData.HasHighCover ? "HighCover" : "LowCover";

        mapData.CurrentStatus = MapCellData.CellStatus.Occupied;
        animator.SetBool(coverType, true);
    }
Example #7
0
 void InitMapData()
 {
     listCells = new List <MapCellData>();
     ClearCellIcons();
     listCellIcons = new List <Image>();
     for (int i = 0; i < mapSize.y; i++)
     {
         for (int j = 0; j < mapSize.x; j++)
         {
             MapCellData freshCell = new MapCellData();
             freshCell.id_inmap = i * mapSize.x + j;
             freshCell.tile_id  = -1;
             listCells.Add(freshCell);
             listCellIcons.Add(null);
         }
     }
 }
Example #8
0
 static void DrawDebug(MapCellData mapCell)
 {
     if (mapCell.CurrentStatus == MapCellData.CellStatus.Collision)
     {
         Debug.DrawLine(mapCell.position, mapCell.position + Vector3.up, Color.red, 20);
     }
     else if (mapCell.HasCover)
     {
         Vector3 direction = Quaternion.AngleAxis(90 * mapCell.Direction, Vector3.up) * Vector3.forward;
         Vector3 origin    = mapCell.position + Vector3.up;
         Debug.DrawLine(origin, origin + direction, Color.green, 20);
     }
     else
     {
         Debug.DrawLine(mapCell.position, mapCell.position + Vector3.up, Color.white, 20);
     }
 }
Example #9
0
    public bool MoveToBetterPositon()
    {
        MapControl.SafePositionRequest posRequest = new MapControl.SafePositionRequest(
            transform.position, unitControl.TeamName, 5);
        posRequest.excludeCenter = true;
        MapCellData myCell   = mapControl.GetData(transform.position);
        MapCellData safeCell = mapControl.GetSafestPosition(posRequest);

        if (safeCell.lastScoreCheck > mapControl.GetCellScore(myCell, unitControl.TeamName))
        {
            unitControl.MoveTo(safeCell.position);
            Debug.Log("Moving to a better position");
            State = "Moving";
            return(true);
        }
        return(false);
    }
 public void Init(MapCtr owner, MapCellData data)
 {
     CellData = data;
     Owner    = owner;
     //
     if (!string.IsNullOrEmpty(data.resName))
     {
         Render.sprite = Resources.Load("Sprites/" + data.resName, typeof(Sprite)) as Sprite;
     }
     else
     {
         Render.sprite = null;
     }
     transform.position      = owner.StartPos + new Vector3(data.col * owner.CellSize.x, data.row * owner.CellSize.y, owner.StartPos.z);
     Render.sortingOrder     = data.sortOrder;
     Render.sortingLayerName = data.sortLayer;
 }
Example #11
0
    Hex InitHex(MapCellData data)
    {
        var position = new Vector2(data.x, data.y);
        var pos      = World.ToPixel(position);
        var hex      = new GameObject();
        var hm       = hex.AddComponent <Hex>();

        hm.data                = data;
        hm.HexPosition         = position;
        hex.transform.position = pos;
        hm.InitializeModel();
        garbage.Add(hex);
        hm.HexModel.meshRenderer.sharedMaterial = new Material(Shader.Find("Diffuse"));


        MapCellTool.OnPropertyChange(hm);
        return(hm);
    }
Example #12
0
    void TestLOS(Vector3 mapPos)
    {
        MapCellData mapCell = GetData(mapPos);

        Debug.Log("Marking " + mapCell.AttackablePositions.Count + " spots");

        GameObject centerObj = GameObject.CreatePrimitive(PrimitiveType.Cube);

        centerObj.transform.position   = mapPos + (Vector3.up * 1.0f);
        centerObj.transform.localScale = Vector3.one * 0.5f;

        foreach (Vector3 pos in mapCell.AttackablePositions)
        {
            GameObject testObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            testObj.transform.position   = pos + (Vector3.up * 0.5f);
            testObj.transform.localScale = Vector3.one * 0.5f;
        }
    }
        private bool UpdateMapCellData(map_start_next startNext)
        {
            var modified = false;

            var mapInfo = GetMapInfoId(startNext);

            if (!this.EnemyData.MapCellDatas.ContainsKey(mapInfo))
            {
                this.EnemyData.MapCellDatas.Add(mapInfo, new List <MapCellData>());
                modified = true;
            }

            var areaId      = startNext.api_maparea_id;
            var mapId       = startNext.api_mapinfo_no;
            var cellId      = startNext.api_no;
            var currentCell = Master.Current.MapAreas[areaId][mapId][cellId];
            var mapCellData = new MapCellData
            {
                MapAreaId = areaId,
                MapInfoIdInEachMapArea = mapId,
                No             = cellId,
                ColorNo        = startNext.api_color_no,
                CommentKind    = startNext.api_comment_kind,
                EventId        = startNext.api_event_id,
                EventKind      = startNext.api_event_kind,
                ProductionKind = startNext.api_production_kind,
                SelectCells    = startNext.api_select_route != null ? startNext.api_select_route.api_select_cells : new int[0],
                Distance       = startNext.api_distance_data?.FirstOrDefault(x => x.api_mapcell_id == currentCell.Id)?.api_distance ?? 0,
            };

            var exists = this.EnemyData.MapCellDatas[mapInfo].FirstOrDefault(x => x.No == mapCellData.No);

            if (!mapCellData.Equals(exists))
            {
                if (exists != null)
                {
                    this.EnemyData.MapCellDatas[mapInfo].Remove(exists);
                }
                this.EnemyData.MapCellDatas[mapInfo].Add(mapCellData);
                modified = true;
            }

            return(modified);
        }
Example #14
0
 public void Init(MapDisplay owner, MapCellData data)
 {
     m_owner    = owner;
     m_data     = data;
     m_addition = (CELL_ADDITION)data.cellAdd;
     m_type     = (CELL_TYPE)data.cellType;
     if (!string.IsNullOrEmpty(data.resName))
     {
         Render.sprite = Resources.Load("Sprites/" + data.resName, typeof(Sprite)) as Sprite;
     }
     else
     {
         Render.sprite = null;
     }
     transform.position = owner.startPos + new Vector3(data.col * owner.cellSize.x, data.row * owner.cellSize.y, owner.startPos.z);
     //Render.sortingLayerID = SortingLayer.GetLayerValueFromID(data.sortLayer);
     Render.sortingOrder     = data.sortOrder;
     Render.sortingLayerName = data.sortLayer;
 }
Example #15
0
    static void TestLOSForCell(Vector3 mapPos, MapControl mapControl)
    {
        MapCellData thisCell = mapControl.GetData(mapPos);

        if (thisCell == null)
        {
            Debug.Log("No Cell Data");
        }
        List <MapCellData> targetCells = mapControl.GetMapArea(mapPos);

        foreach (MapCellData targetCell in targetCells)
        {
            if (CheckLOS(targetCell.position, thisCell.position, true))
            {
                thisCell.AttackablePositions.Add(targetCell.position);
            }
        }
        Debug.Log("Adding " + thisCell.AttackablePositions.Count + " positions for " + thisCell.position);
    }
Example #16
0
    [PunRPC] void RPC_PlaceSilo(byte[] id_bytes, byte[] x_bytes, byte[] y_bytes)
    {
        int     received_id     = BitConverter.ToInt32(id_bytes, 0);
        Vector2 received_coords = new Vector2(BitConverter.ToSingle(x_bytes, 0), BitConverter.ToSingle(y_bytes, 0));

        Debug.Log("Placing silo on " + received_coords + " for player " + received_id);
        MapCellData cell = data.map[(int)received_coords.x, (int)received_coords.y];

        if (cell.owner_id != received_id)
        {
            return;
        }
        if (cell.has_silo)
        {
            return;
        }
        cell.has_silo = true;
        players_in_match[received_id].silos.Add(cell);
        UpdatePlayerMap();
    }
    static void SetAStarMapCell_Second(MapData map, MapCellData cell, ref AStarMap astarMap)
    {
        // check second time
        CELL_TYPE curType = (CELL_TYPE)cell.cellType;

        if (curType == CELL_TYPE.STONE || curType == CELL_TYPE.WALL)
        {
            return;
        }
        if (cell.row - 1 >= 0)
        {
            MapCellData downCell = map.cells [(cell.row - 1) * map.column + cell.col];
            CELL_TYPE   downType = (CELL_TYPE)downCell.cellType;
            if (downType == CELL_TYPE.WALL || downType == CELL_TYPE.STONE ||
                downType == CELL_TYPE.LADDER)
            {
                //right
                if (cell.col + 1 < map.column)
                {
                    MapCellData rightCell = map.cells [(cell.row) * map.column + cell.col + 1];
                    CELL_TYPE   rightType = (CELL_TYPE)rightCell.cellType;
                    if (rightType != CELL_TYPE.WALL && rightType != CELL_TYPE.STONE)
                    {
                        //astarMapCell.IsToRight = true;
                        astarMap.GetCell(rightCell.row, rightCell.col).IsToLeft = true;
                    }
                }
                //left
                if (cell.col - 1 >= 0)
                {
                    MapCellData leftCell = map.cells [(cell.row) * map.column + cell.col - 1];
                    CELL_TYPE   leftType = (CELL_TYPE)leftCell.cellType;
                    if (leftType != CELL_TYPE.WALL && leftType != CELL_TYPE.STONE)
                    {
                        //astarMapCell.IsToLeft = true;
                        astarMap.GetCell(leftCell.row, leftCell.col).IsToRight = true;
                    }
                }
            }
        }
    }
Example #18
0
 public void CreateMap(int height = 0)
 {
     map           = ScriptableObject.CreateInstance <MapData>();
     map.cells     = new MapCellData[mapHeight * mapWidth];
     map.hexs      = new Hex[mapHeight * mapWidth];
     map.mapWidth  = mapWidth;
     map.mapHeight = mapHeight;
     for (int j = 0; j < mapHeight; j++)
     {
         for (int i = 0; i < mapWidth; i++)
         {
             var data = new MapCellData();
             data.id            = i + j * mapWidth;
             data.x             = i;
             data.y             = j;
             map.cells[data.id] = data;
             var hex = InitHex(data);
             map.hexs[data.id] = hex;
         }
     }
 }
Example #19
0
    public void CleanNullCell()
    {
        var oldList = cell_datas;

        cell_datas = new List <MapCellData>();
        for (int i = 0; i < oldList.Count; i++)
        {
            var freshCell = new MapCellData();
            freshCell.id_inmap = oldList[i].id_inmap;
            freshCell.rot      = oldList[i].rot;
            freshCell.tile_id  = oldList[i].tile_id;
            cell_datas.Add(freshCell);
        }
        for (int i = cell_datas.Count - 1; i >= 0; i--)
        {
            if (cell_datas[i].tile_id < 0)
            {
                cell_datas.RemoveAt(i);
            }
        }
    }
        private void UpdateMapCellData(map_start_next startNext)
        {
            var mapInfo = GetMapInfo(startNext);

            if (!this.EnemyData.MapCellDatas.ContainsKey(mapInfo))
            {
                this.EnemyData.MapCellDatas.Add(mapInfo, new List <MapCellData>());
            }

            var currentCell = Master.Current.MapCells
                              .Select(x => x.Value)
                              .Where(x => x.MapAreaId == startNext.api_maparea_id)
                              .Where(x => x.MapInfoIdInEachMapArea == startNext.api_mapinfo_no)
                              .FirstOrDefault(x => x.IdInEachMapInfo == startNext.api_no);
            var mapCellData = new MapCellData
            {
                MapAreaId = startNext.api_maparea_id,
                MapInfoIdInEachMapArea = startNext.api_mapinfo_no,
                No             = startNext.api_no,
                ColorNo        = startNext.api_color_no,
                CommentKind    = startNext.api_comment_kind,
                EventId        = startNext.api_event_id,
                EventKind      = startNext.api_event_kind,
                ProductionKind = startNext.api_production_kind,
                SelectCells    = startNext.api_select_route != null ? startNext.api_select_route.api_select_cells : new int[0],
                Distance       = startNext.api_distance_data?.FirstOrDefault(x => x.api_mapcell_id == currentCell.Id)?.api_distance ?? 0,
            };

            var exists = this.EnemyData.MapCellDatas[mapInfo].SingleOrDefault(x => x.No == mapCellData.No);

            if (exists != null)
            {
                this.EnemyData.MapCellDatas[mapInfo].Remove(exists);
            }
            this.EnemyData.MapCellDatas[mapInfo].Add(mapCellData);
        }
Example #21
0
 public void SetData(MapCellData data)
 {
     this.data = data;
 }
Example #22
0
    public UnitControl ScanForTargets(UnitControl excludeThisGuy)
    {
        GameObject[] possibleTargets = GameObject.FindGameObjectsWithTag("Unit");
        LayerMask    layerMask       = 1 << LayerMask.NameToLayer("Terrain");
        float        closestDistance = Mathf.Infinity;
        GameObject   closestTarget   = null;

        foreach (GameObject target in possibleTargets)
        {
            if (target.name.Contains(unitControl.TeamName))
            {
                continue;
            }

            UnitControl targetControl = target.GetComponent <UnitControl>();
            if (!targetControl || targetControl.IsDead)
            {
                continue;
            }

            if (excludeThisGuy && excludeThisGuy.Equals(targetControl))
            {
                continue;
            }

            float targetDistance = Vector3.Distance(
                target.transform.position,
                transform.position
                );
            if (targetDistance > visualRange)
            {
                continue;
            }

            if (closestTarget && closestDistance < targetDistance)
            {
                continue;
            }

            Ray ray = new Ray(
                transform.position + (Vector3.up * 0.75f),
                (target.transform.position - transform.position).normalized
                );

            Debug.DrawRay(ray.origin, ray.direction * targetDistance, Color.green, 1.0f);

            bool canHit = false;
            if (!canHit)
            {
                MapCellData myCell = mapControl.GetData(transform.position);
                foreach (Vector3 otherPosition in myCell.ExtraFiringPositions)
                {
                    ray.origin = otherPosition;
                    canHit     = !Physics.Raycast(ray, targetDistance, layerMask);
                    if (canHit)
                    {
                        break;
                    }
                }
            }

            if (canHit)
            {
                closestTarget   = target;
                closestDistance = targetDistance;
            }
        }
        if (closestTarget)
        {
            UnitControl targetControl = closestTarget.GetComponent <UnitControl>();
            if (!targetControl)
            {
                Debug.Log(closestTarget.name + " doesn't have a unitControl");
            }

            return(targetControl);
        }
        else
        {
            Debug.Log(transform.name + "'s scan found noone");
            return(null);
        }
    }
Example #23
0
    public float GetCellScore(MapCellData mapCell, string teamName)
    {
        float score = 0.0f;

        if (mapCell.HasCover)
        {
            score += 0.6f;
        }
        if (mapCell.HasHighCover)
        {
            score += 0.6f;
        }

        GameObject[] attackers = GameObject.FindGameObjectsWithTag("Unit");

        foreach (GameObject enemy in attackers)
        {
            if (enemy.name.Contains(teamName))
            {
                continue;
            }

            MapCellData enemyCell   = GetData(enemy.transform.position);
            float       sqrDistance = (mapCell.position - enemyCell.position).sqrMagnitude;

            if (mapCell.AttackablePositions.Contains(enemyCell.position))
            {
                if (sqrDistance < (16 * gridSize))
                {
                    score -= 3.0f;
                }
                else if (sqrDistance < (32 * gridSize))
                {
                    score -= 2.0f;
                }
                else
                {
                    score -= 1.0f;
                }
            }

            if (enemyCell.ExtraAttackablePositions.Contains(mapCell.position))
            {
                if (sqrDistance < (16 * gridSize))
                {
                    score -= 1.0f;
                }
                else if (sqrDistance < (32 * gridSize))
                {
                    score -= 0.5f;
                }
                else
                {
                    score -= 0.25f;
                }
            }

            if (mapCell.ExtraAttackablePositions.Contains(enemyCell.position))
            {
                score += 1.0f;
            }

            if (sqrDistance < (5 * gridSize))
            {
                score -= 5.0f;
            }
        }
        mapCell.lastScoreCheck = score;
        return(score);
    }
Example #24
0
    public float GetCellScore(Vector3 mapPos, string teamName)
    {
        MapCellData mapCell = GetData(mapPos);

        return(GetCellScore(mapCell, teamName));
    }
    static void SetAStarMapCell_First(MapData map, MapCellData cell, ref AStarMap astarMap)
    {
        AStarMapCell astarMapCell = astarMap.GetCell(cell.row, cell.col);

        astarMapCell.IsToLeftUp    = false;
        astarMapCell.IsToLeftDown  = false;
        astarMapCell.IsToRightUp   = false;
        astarMapCell.IsToRightDown = false;

        //check up
        if (cell.row + 1 < map.row)
        {
            MapCellData  upCell      = map.cells [(cell.row + 1) * map.column + cell.col];
            AStarMapCell upAStarCell = astarMap.GetCell(cell.row + 1, cell.col);
            switch ((CELL_TYPE)cell.cellType)
            {
            case CELL_TYPE.WALL:
                upAStarCell.IsToDown = false;
                astarMapCell.IsToUp  = false;
                break;

            case CELL_TYPE.STONE:
                upAStarCell.IsToDown = false;
                astarMapCell.IsToUp  = false;
                break;

            case CELL_TYPE.LADDER:
                switch ((CELL_TYPE)upCell.cellType)
                {
                case CELL_TYPE.WALL:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = false;
                    break;

                case CELL_TYPE.STONE:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = false;
                    break;

                case CELL_TYPE.LADDER:
                    upAStarCell.IsToDown = true;
                    astarMapCell.IsToUp  = true;
                    break;

                case CELL_TYPE.POLE:
                    upAStarCell.IsToDown = true;
                    astarMapCell.IsToUp  = true;
                    break;

                case CELL_TYPE.NONE:
                    upAStarCell.IsToDown = true;
                    astarMapCell.IsToUp  = true;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    upAStarCell.IsToDown = true;
                    astarMapCell.IsToUp  = true;
                    break;
                }
                break;

            case CELL_TYPE.POLE:
                switch ((CELL_TYPE)upCell.cellType)
                {
                case CELL_TYPE.WALL:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = false;
                    break;

                case CELL_TYPE.STONE:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = false;
                    break;

                case CELL_TYPE.LADDER:
                    upAStarCell.IsToDown = true;
                    astarMapCell.IsToUp  = true;
                    break;

                case CELL_TYPE.POLE:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = false;
                    break;

                case CELL_TYPE.NONE:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = true;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = true;
                    break;
                }
                break;

            case CELL_TYPE.NONE:
                switch ((CELL_TYPE)upCell.cellType)
                {
                case CELL_TYPE.WALL:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = false;
                    break;

                case CELL_TYPE.STONE:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = false;
                    break;

                case CELL_TYPE.LADDER:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = true;
                    break;

                case CELL_TYPE.POLE:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = true;
                    break;

                case CELL_TYPE.NONE:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = true;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = true;
                    break;
                }
                break;

            default:            //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                switch ((CELL_TYPE)upCell.cellType)
                {
                case CELL_TYPE.WALL:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = false;
                    break;

                case CELL_TYPE.STONE:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = false;
                    break;

                case CELL_TYPE.LADDER:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = true;
                    break;

                case CELL_TYPE.POLE:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = true;
                    break;

                case CELL_TYPE.NONE:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = true;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    upAStarCell.IsToDown = false;
                    astarMapCell.IsToUp  = true;
                    break;
                }
                break;
            }
        }
        //down
        if (cell.row - 1 >= 0)
        {
            MapCellData  downCell      = map.cells [(cell.row - 1) * map.column + cell.col];
            AStarMapCell downAStarCell = astarMap.GetCell(cell.row - 1, cell.col);
            switch ((CELL_TYPE)cell.cellType)
            {
            case CELL_TYPE.WALL:
                astarMapCell.IsToDown = false;
                downAStarCell.IsToUp  = false;
                break;

            case CELL_TYPE.STONE:
                astarMapCell.IsToDown = false;
                downAStarCell.IsToUp  = false;
                break;

            case CELL_TYPE.LADDER:
                switch ((CELL_TYPE)downCell.cellType)
                {
                case CELL_TYPE.WALL:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = false;
                    break;

                case CELL_TYPE.STONE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = false;
                    break;

                case CELL_TYPE.LADDER:
                    astarMapCell.IsToDown = true;
                    downAStarCell.IsToUp  = true;
                    break;

                case CELL_TYPE.POLE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;

                case CELL_TYPE.NONE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;
                }
                break;

            case CELL_TYPE.POLE:
                switch ((CELL_TYPE)downCell.cellType)
                {
                case CELL_TYPE.WALL:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = false;
                    break;

                case CELL_TYPE.STONE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = false;
                    break;

                case CELL_TYPE.LADDER:
                    astarMapCell.IsToDown = true;
                    downAStarCell.IsToUp  = true;
                    break;

                case CELL_TYPE.POLE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;

                case CELL_TYPE.NONE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;
                }
                break;

            case CELL_TYPE.NONE:
                switch ((CELL_TYPE)downCell.cellType)
                {
                case CELL_TYPE.WALL:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = false;
                    break;

                case CELL_TYPE.STONE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = false;
                    break;

                case CELL_TYPE.LADDER:
                    astarMapCell.IsToDown = true;
                    downAStarCell.IsToUp  = true;
                    break;

                case CELL_TYPE.POLE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;

                case CELL_TYPE.NONE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;
                }
                break;

            default:            //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                switch ((CELL_TYPE)downCell.cellType)
                {
                case CELL_TYPE.WALL:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = false;
                    break;

                case CELL_TYPE.STONE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = false;
                    break;

                case CELL_TYPE.LADDER:
                    astarMapCell.IsToDown = true;
                    downAStarCell.IsToUp  = true;
                    break;

                case CELL_TYPE.POLE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;

                case CELL_TYPE.NONE:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    astarMapCell.IsToDown = false;
                    downAStarCell.IsToUp  = true;
                    break;
                }
                break;
            }
        }
        //check left
        if (cell.col - 1 >= 0)
        {
            MapCellData  leftCell      = map.cells [(cell.row) * map.column + cell.col - 1];
            AStarMapCell leftAStarCell = astarMap.GetCell(cell.row, cell.col - 1);
            switch ((CELL_TYPE)cell.cellType)
            {
            case CELL_TYPE.WALL:
                leftAStarCell.IsToRight = false;
                astarMapCell.IsToLeft   = false;
                break;

            case CELL_TYPE.STONE:
                leftAStarCell.IsToRight = false;
                astarMapCell.IsToLeft   = false;
                break;

            case CELL_TYPE.LADDER:
                switch ((CELL_TYPE)leftCell.cellType)
                {
                case CELL_TYPE.WALL:
                    leftAStarCell.IsToRight = false;
                    astarMapCell.IsToLeft   = false;
                    break;

                case CELL_TYPE.STONE:
                    leftAStarCell.IsToRight = false;
                    astarMapCell.IsToLeft   = false;
                    break;

                case CELL_TYPE.LADDER:
                    leftAStarCell.IsToRight = true;
                    astarMapCell.IsToLeft   = true;
                    break;

                case CELL_TYPE.POLE:
                    leftAStarCell.IsToRight = true;
                    astarMapCell.IsToLeft   = true;
                    break;

                case CELL_TYPE.NONE:
                    leftAStarCell.IsToRight = true;
                    astarMapCell.IsToLeft   = false;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    leftAStarCell.IsToRight = true;
                    astarMapCell.IsToLeft   = false;
                    break;
                }
                break;

            case CELL_TYPE.POLE:
                switch ((CELL_TYPE)leftCell.cellType)
                {
                case CELL_TYPE.WALL:
                    leftAStarCell.IsToRight = false;
                    astarMapCell.IsToLeft   = false;
                    break;

                case CELL_TYPE.STONE:
                    leftAStarCell.IsToRight = false;
                    astarMapCell.IsToLeft   = false;
                    break;

                case CELL_TYPE.LADDER:
                    leftAStarCell.IsToRight = true;
                    astarMapCell.IsToLeft   = true;
                    break;

                case CELL_TYPE.POLE:
                    leftAStarCell.IsToRight = true;
                    astarMapCell.IsToLeft   = true;
                    break;

                case CELL_TYPE.NONE:
                    leftAStarCell.IsToRight = true;
                    astarMapCell.IsToLeft   = false;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    leftAStarCell.IsToRight = true;
                    astarMapCell.IsToLeft   = false;
                    break;
                }
                break;

            default:            //case CELL_TYPE.NONE || CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                switch ((CELL_TYPE)leftCell.cellType)
                {
                case CELL_TYPE.WALL:
                    leftAStarCell.IsToRight = false;
                    astarMapCell.IsToLeft   = false;
                    break;

                case CELL_TYPE.STONE:
                    leftAStarCell.IsToRight = false;
                    astarMapCell.IsToLeft   = false;
                    break;

                case CELL_TYPE.LADDER:
                    leftAStarCell.IsToRight = false;
                    astarMapCell.IsToLeft   = true;
                    break;

                case CELL_TYPE.POLE:
                    leftAStarCell.IsToRight = false;
                    astarMapCell.IsToLeft   = true;
                    break;

                case CELL_TYPE.NONE:
                    leftAStarCell.IsToRight = false;
                    astarMapCell.IsToLeft   = false;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    leftAStarCell.IsToRight = false;
                    astarMapCell.IsToLeft   = false;
                    break;
                }
                break;
            }
        }
        //check right
        if (cell.col + 1 < map.column)
        {
            MapCellData  rightCell      = map.cells [(cell.row) * map.column + cell.col + 1];
            AStarMapCell rightAStarCell = astarMap.GetCell(cell.row, cell.col + 1);
            switch ((CELL_TYPE)cell.cellType)
            {
            case CELL_TYPE.WALL:
                astarMapCell.IsToRight  = false;
                rightAStarCell.IsToLeft = false;
                break;

            case CELL_TYPE.STONE:
                astarMapCell.IsToRight  = false;
                rightAStarCell.IsToLeft = false;
                break;

            case CELL_TYPE.LADDER:
                switch ((CELL_TYPE)rightCell.cellType)
                {
                case CELL_TYPE.WALL:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = false;
                    break;

                case CELL_TYPE.STONE:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = false;
                    break;

                case CELL_TYPE.LADDER:
                    astarMapCell.IsToRight  = true;
                    rightAStarCell.IsToLeft = true;
                    break;

                case CELL_TYPE.POLE:
                    astarMapCell.IsToRight  = true;
                    rightAStarCell.IsToLeft = true;
                    break;

                case CELL_TYPE.NONE:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = true;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = true;
                    break;
                }
                break;

            case CELL_TYPE.POLE:
                switch ((CELL_TYPE)rightCell.cellType)
                {
                case CELL_TYPE.WALL:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = false;
                    break;

                case CELL_TYPE.STONE:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = false;
                    break;

                case CELL_TYPE.LADDER:
                    astarMapCell.IsToRight  = true;
                    rightAStarCell.IsToLeft = true;
                    break;

                case CELL_TYPE.POLE:
                    astarMapCell.IsToRight  = true;
                    rightAStarCell.IsToLeft = true;
                    break;

                case CELL_TYPE.NONE:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = true;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = true;
                    break;
                }
                break;

            default:            //case CELL_TYPE.NONE || CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                switch ((CELL_TYPE)rightCell.cellType)
                {
                case CELL_TYPE.WALL:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = false;
                    break;

                case CELL_TYPE.STONE:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = false;
                    break;

                case CELL_TYPE.LADDER:
                    astarMapCell.IsToRight  = true;
                    rightAStarCell.IsToLeft = false;
                    break;

                case CELL_TYPE.POLE:
                    astarMapCell.IsToRight  = true;
                    rightAStarCell.IsToLeft = false;
                    break;

                case CELL_TYPE.NONE:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = false;
                    break;

                default:                //case CELL_TYPE.BRA || CELL_TYPE.UNDERPANT || CELL_TYPE.SOCKS:
                    astarMapCell.IsToRight  = false;
                    rightAStarCell.IsToLeft = false;
                    break;
                }
                break;
            }
        }
    }
Example #26
0
    static void FillOutMapData(MapControl mapControl)
    {
        Vector2 mapSize   = mapControl.GetMapSize();
        Vector3 mapCenter = mapControl.transform.position - new Vector3(mapSize.x / 2, 0, mapSize.y / 2);

        Debug.Log("mapSize is " + mapSize);
        Debug.Log("MapCenter is " + mapCenter);

        for (int x = 0; x < mapSize.x; x++)
        {
            for (int y = 0; y < mapSize.y; y++)
            {
                MapCellData mapCell = new MapCellData();
                mapCell.gridSize = mapControl.gridSize;

                RaycastHit hit;
                Ray        ray = new Ray(new Vector3((x) * mapControl.gridSize, 10.0f, (y) * mapControl.gridSize) + mapCenter, Vector3.down);

                LayerMask terrainMask = 1 << LayerMask.NameToLayer("Terrain");
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, terrainMask))
                {
                    mapCell.position = hit.point;
                    mapCell.Cover    = GetCover(mapCell.position, mapControl.gridSize);

                    if (hit.transform.tag.Equals("HighCover") || hit.transform.tag.Equals("LowCover"))
                    {
                        mapCell.CurrentStatus = MapCellData.CellStatus.Collision;
                    }
                }

                int xPos = Mathf.FloorToInt(x);
                int yPos = Mathf.FloorToInt(y);


                mapControl.mapData[yPos * Mathf.FloorToInt(mapSize.x) + xPos] = mapCell;
                DrawDebug(mapCell);
            }
        }

        //Second Pass for line of sight data
        for (int x = 0; x < mapSize.x; x++)
        {
            for (int y = 0; y < mapSize.y; y++)
            {
                Vector2     mapCoor  = new Vector2(x, y);
                MapCellData thisCell = mapControl.GetData(mapCoor);
                if (thisCell == null)
                {
                    Debug.Log("No Cell Data");
                    continue;
                }
                if (thisCell.CurrentStatus == MapCellData.CellStatus.Collision)
                {
                    continue;
                }

                List <MapCellData> targetCells = mapControl.GetMapArea(mapCoor);
                foreach (MapCellData targetCell in targetCells)
                {
                    if (CheckLOS(targetCell.position, thisCell.position))
                    {
                        if (!thisCell.AttackablePositions.Contains(targetCell.position))
                        {
                            thisCell.AttackablePositions.Add(targetCell.position);
                        }
                    }
                    foreach (Vector3 extraPos in thisCell.ExtraFiringPositions)
                    {
                        if (CheckLOS(targetCell.position, extraPos) &&
                            !CheckLOS(targetCell.position, thisCell.position))
                        {
                            thisCell.ExtraAttackablePositions.Add(targetCell.position);
                        }
                    }
                }
            }
        }
    }
 public static void ResetAStarMapCell(MapData map, MapCellData cell, ref AStarMap astarMap)
 {
     SetAStarMapCell_First(map, cell, ref astarMap);
     SetAStarMapCell_Second(map, cell, ref astarMap);
 }