Esempio n. 1
0
        public void SetAllFOW(FogOfWar f, CollisionGrid cg)
        {
            int i = f == FogOfWar.Nothing ? HEAT_NONE : (f == FogOfWar.Passive ? HEAT_PASSIVE : HEAT_PASSIVE + 1);

            for (int y = 0; y < cg.numCells.Y; y++)
            {
                for (int x = 0; x < cg.numCells.X; x++)
                {
                    heat[x, y] = i;
                    cg.SetFogOfWar(x, y, teamIndex, f);
                }
            }
        }
Esempio n. 2
0
 public void SetAllFOW(FogOfWar f, CollisionGrid cg)
 {
     int i = f == FogOfWar.Nothing ? HEAT_NONE : (f == FogOfWar.Passive ? HEAT_PASSIVE : HEAT_PASSIVE + 1);
     for(int y = 0; y < cg.numCells.Y; y++) {
         for(int x = 0; x < cg.numCells.X; x++) {
             heat[x, y] = i;
             cg.SetFogOfWar(x, y, teamIndex, f);
         }
     }
 }
Esempio n. 3
0
        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;
        }