private bool IsGood(int gx, int gy, int[,] val, ref FOWPoint p) { if (p.X >= 0 && p.X < gx && p.Y >= 0 && p.Y < gy) { return(val[p.X, p.Y] < p.TravelAmount); } else { return(false); } }
private bool IsGood(int gx, int gy, int[,] val, ref FOWPoint p) { if(p.X >= 0 && p.X < gx && p.Y >= 0 && p.Y < gy) { return val[p.X, p.Y] < p.TravelAmount; } else return false; }
private bool InBounds(int gx, int gy, ref FOWPoint p) { return p.X >= 0 && p.X < gx && p.Y >= 0 && p.Y < gy; }
private void AddPoints(int gx, int gy, int[,] val, Queue<FOWPoint> q, ref FOWPoint prev) { FOWPoint fp; switch(prev.PreviousDirection) { case TravelDirection.PX: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXPY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXNY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PX, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); break; case TravelDirection.NX: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXPY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXNY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NX, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); break; case TravelDirection.PY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXPY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXPY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); break; case TravelDirection.NY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXNY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXNY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); break; case TravelDirection.PXPY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXPY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PX, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); break; case TravelDirection.PXNY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXNY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PX, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); break; case TravelDirection.NXNY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXNY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NX, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); break; case TravelDirection.NXPY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXPY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NX, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PY, prev.TravelAmount); if(IsGood(gx, gy, val, ref fp)) q.Enqueue(fp); break; } }
public override void DoWork(float dt) { RTSTeam team = state.teams[teamIndex]; CollisionGrid cg = state.CGrid; // Generate All The Old FOW int[,] val = new int[cg.numCells.X, cg.numCells.Y]; for (int y = 0; y < cg.numCells.Y; y++) { for (int x = 0; x < cg.numCells.X; x++) { // Set To Passive If There Was Some Visibility if (heat[x, y] > HEAT_NONE) { val[x, y] = HEAT_PASSIVE * 10; } else { val[x, y] = 0; } } } // Add Starting Points To The Queue var queue = new Queue <FOWPoint>(); for (int i = 0; i < team.Units.Count; i++) { Point p = HashHelper.Hash(team.Units[i].GridPosition, cg.numCells, cg.size); int vRadius = (int)(team.Units[i].Data.BaseCombatData.MaxRange / cg.cellSize); vRadius *= 10; if (val[p.X, p.Y] < vRadius) { queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.PXPY, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.NXNY, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.NXPY, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.PXNY, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.PX, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.NX, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.PY, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.NY, vRadius)); cg.SetFogOfWar(p.X, p.Y, teamIndex, FogOfWar.Active); val[p.X, p.Y] = vRadius; } } for (int i = 0; i < team.Buildings.Count; i++) { Point p = HashHelper.Hash(team.Buildings[i].GridPosition, cg.numCells, cg.size); int vRadius = (int)(team.Buildings[i].Data.SightRadius / cg.cellSize); vRadius *= 10; if (val[p.X, p.Y] < vRadius) { queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.PXPY, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.NXNY, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.NXPY, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.PXNY, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.PX, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.NX, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.PY, vRadius)); queue.Enqueue(new FOWPoint(p.X, p.Y, TravelDirection.NY, vRadius)); cg.SetFogOfWar(p.X, p.Y, teamIndex, FogOfWar.Active); val[p.X, p.Y] = vRadius; } } // Fan Out Heat while (queue.Count > 0) { FOWPoint fp = queue.Dequeue(); if (InBounds(cg.numCells.X, cg.numCells.Y, ref fp) && val[fp.X, fp.Y] < fp.TravelAmount) { val[fp.X, fp.Y] = fp.TravelAmount; AddPoints(cg.numCells.X, cg.numCells.Y, val, queue, ref fp); } } // Set The Fog Of War To The Grid for (int y = 0; y < cg.numCells.Y; y++) { for (int x = 0; x < cg.numCells.X; x++) { FogOfWar f = cg.GetFogOfWar(x, y, teamIndex); val[x, y] /= 10; switch (val[x, y]) { case HEAT_PASSIVE: if (f != FogOfWar.Passive) { cg.SetFogOfWar(x, y, teamIndex, FogOfWar.Passive); } break; case 0: // Black, But Don't Do Anything break; default: // Active if (f != FogOfWar.Active) { cg.SetFogOfWar(x, y, teamIndex, FogOfWar.Active); } break; } } } heat = val; }
private void AddPoints(int gx, int gy, int[,] val, Queue <FOWPoint> q, ref FOWPoint prev) { FOWPoint fp; switch (prev.PreviousDirection) { case TravelDirection.PX: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXPY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXNY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PX, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } break; case TravelDirection.NX: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXPY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXNY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NX, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } break; case TravelDirection.PY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXPY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXPY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } break; case TravelDirection.NY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXNY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXNY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } break; case TravelDirection.PXPY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXPY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PX, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } break; case TravelDirection.PXNY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PXNY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PX, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } break; case TravelDirection.NXNY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXNY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NX, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } break; case TravelDirection.NXPY: fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NXPY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.NX, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } fp = new FOWPoint(prev.X, prev.Y, TravelDirection.PY, prev.TravelAmount); if (IsGood(gx, gy, val, ref fp)) { q.Enqueue(fp); } break; } }
private bool InBounds(int gx, int gy, ref FOWPoint p) { return(p.X >= 0 && p.X < gx && p.Y >= 0 && p.Y < gy); }