/// <summary> /// PathFinding main method /// </summary> /// <param name="startingCells"></param> /// <param name="exitCells"></param> /// <param name="selectFartherCells"></param> /// <param name="firstStepOnly"></param> /// <returns></returns> private int SubMapFiller(CellInfo startingCell, byte RegionNb) { Debug.Assert(RegionNb > 0); // If a wrong or non-walkable cell or already with the given Region number, then return 0. if ((startingCell == null) || !_map.IsCellWalkable(startingCell.Cell, true, null) || !(!_isInFight || startingCell.IsCombatWalkable) || (startingCell.SubMapId == RegionNb) ) { return(0); } _isInFight = false; Random rnd = new Random(); List <CellInfo> changed = new List <CellInfo>(); List <CellInfo> changing; int cellCounter = 0; startingCell.SubMapId = RegionNb; changed.Add(startingCell); while (changed.Count > 0) { cellCounter += changed.Count; changing = new List <CellInfo>(); // Look at each square on the board. foreach (CellInfo curCell in changed) { //Debug.Assert((curCell != null && curCell.distanceSteps < CellInfo.DEFAULT_DISTANCE)); foreach (CellInfo newCell in ValidMoves(curCell, true)) { if (newCell.SubMapId != RegionNb && _map.IsCellWalkable(newCell.Cell, true, null) && (!_isInFight || newCell.IsCombatWalkable)) { newCell.SubMapId = RegionNb; changing.Add(newCell); } } } changed = changing; } return(cellCounter); }
private bool SquareOpen(CellInfo cell, CellInfo originCell = null) { if (cell == null) { return(false); } if (cell.IsOpen == null) { if (_isInFight) { cell.IsOpen = cell.IsCombatWalkable && _map.IsCellWalkable(cell.Cell, false, originCell == null ? null : originCell.Cell) /* && !cell.IsCloseToEnemy*/; } else { cell.IsOpen = _map.IsCellWalkable(cell.Cell, !_isCautious, originCell == null ? null : originCell.Cell) /* && (!_isCautious || !cell.IsCloseToEnemy)*/; } } return(cell.IsOpen.Value); }