public void FieldOfViewUpdate() { UInt16 range = this.StatSightRange; //Map currentMap = this.InhabitedMap; if (range < 0) { return; } //REMOVE REDUNDANCY HERE BitArray[] update = new BitArray[_inhabitedMap.BoundX]; for (int i = 0; i < _inhabitedMap.BoundX; ++i) { update[i] = new BitArray(_inhabitedMap.BoundY); } for (Int32 i = -range + 1; i < range; i++) { for (Int32 j = -range + 1; j < range; j++) { Coords current = new Coords(CoordsType.Tile, _positionTile.X + i, _positionTile.Y + j); if ( !_myCollider.CheckInBounds(current) || (StaticMathFunctions.DistanceBetweenTwoCoordsEucledean(this._positionTile, current) > range) ) { continue; } bool val = _myVisibilityTracker.RayTracerVisibilityCheckTile(this._positionTile, current, false); update[current.X][current.Y] = val; } } // determine values that were changed for (int i = 0; i < _inhabitedMap.BoundX; ++i) { update[i] = update[i].Xor(_fieldOfView[i]); } // update changes for (int i = 0; i < _inhabitedMap.BoundX; ++i) { for (int j = 0; j < _inhabitedMap.BoundY; ++j) { if (update[i][j]) { bool val = _fieldOfView[i][j]; _fieldOfView[i][j] = !val; //_inhabitedMap.GetTile(i, j).VisibilityUpdate(this, !val); _myVisibilityTracker.VisibilityUpdate(new Coords(CoordsType.Tile, i, j), this, !val); } } } }
/// <summary> /// Returns list of possible moves, sorted by /// 1) amount of increase, 2) distance to influence map source /// THIS METHOD SHOULD BE IMPROVED /// </summary> public List <Direction> PossibleMoves(Coords currentPosition) { List <Direction> dirList = new List <Direction>(); // Dangerous cast? TilePassable currentTile = (TilePassable)this._currentMap.GetTile(currentPosition); for (byte i = 1; i <= 8; i++) { Direction currentDir = (Direction)i; if (currentTile.AllowedMovesCheckInDirection(currentDir)) { dirList.Add(currentDir); } } dirList.Sort( delegate(Direction d1, Direction d2) { Coords c1 = StaticMathFunctions.CoordsNeighboringInDirection(currentPosition, d1); Coords c2 = StaticMathFunctions.CoordsNeighboringInDirection(currentPosition, d2); Int32 returnVal = (this._influenceMap[c1.X, c1.Y]).CompareTo(this._influenceMap[c2.X, c2.Y]); if (returnVal == 0) { returnVal = (StaticMathFunctions.DistanceBetweenTwoCoordsEucledean(c1, currentPosition)).CompareTo (StaticMathFunctions.DistanceBetweenTwoCoordsEucledean(c2, currentPosition)); } return(returnVal); } ); return(dirList); }