/// <summary> /// Creates a DefaultFOVVisibilityHandler that will manage visibility of objects for the given map as noted in the class description. /// </summary> /// <param name="map">The map this handler will manage visibility for.</param> /// <param name="unexploredColor">Foreground color to set to all terrain tiles that are outside of FOV but have been explored.</param> /// <param name="startingState">The starting state to put the handler in.</param> public MagiRogueFOVVisibilityHandler(Map map, Color unexploredColor, int ghostLayer, FovState startingState = FovState.Enabled) : base(map, startingState) { ExploredColorTint = unexploredColor; _ghostLayer = ghostLayer; }
public static List <Point> TraceFov(Point point, int radius, TraceDelegate cb = null, object ctx = null) { FovState state = new FovState(); List <Point> visited = new List <Point>(); state.visited = visited; state.originalCb = cb; state.originalContext = ctx; if (cb != null) { int res = cb(point, ctx); if (res < 0) { return(visited); } } visited.Add(point); int n = radius * 24; double dtheta = 2.0 * Math.PI / n; for (int t = 0; t < n; t++) { double theta = t * dtheta; int x = (int)Math.Round((radius * Math.Cos(theta))); int y = (int)Math.Round((radius * Math.Sin(theta))); Point end = new Point(point.X + x, point.Y + y); TraceLine(point, end, FovCallback, state); } return(visited); }
private static int FovCallback(Point point, object ctx) { FovState state = (FovState)ctx; foreach (Point p in state.visited) { if (p.X == point.X && p.Y == point.Y) { return(0); } } if (state.originalCb != null) { int res = state.originalCb(point, state.originalContext); if (res < 0) { return(res); } } state.visited.Add(point); return(0); }