/// <summary> /// Given an old position and a direction, this method returns /// a new position based on that direction. /// </summary> /// <param name="oldPos">The old position.</param> /// <param name="direction">The direction to move.</param> /// <returns>The new position.</returns> public static Position GetNewPosition(Position oldPos, Direction direction) { Position pos = oldPos.Clone(); switch (direction) { case Direction.NORTH: pos.y--; break; case Direction.EAST: pos.x++; break; case Direction.SOUTH: pos.y++; break; case Direction.WEST: pos.x--; break; default: Log.WriteLine("Unknown direction: " + direction); break; } return pos; }
/// <summary> /// Gets a position for which a creature could be added. /// Returns null if all the spaces around this position are taken. /// </summary> /// <param name="curPos">The position to add the creature.</param> /// <param name="creatureFor">The creature to add.</param> /// <returns>A free space or null if all spaces are taken.</returns> public Position GetFreePosition(Position curPos, Creature creatureFor) { Position tempPos = curPos.Clone(); if (!TileContainsType(curPos, Constants.TYPE_BLOCKS_AUTO_WALK)) { return tempPos; } for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { tempPos.x = (ushort)(curPos.x + i); tempPos.y = (ushort)(curPos.y + j); if (!TileContainsType(tempPos, Constants.TYPE_BLOCKS_AUTO_WALK)) { return tempPos; } } } return null; }