Beispiel #1
0
        public void UpdateVisible(CollisionGrid cg)
        {
            // All Team Friendly Units Are Visible
            BoundingFrustum frustum = new BoundingFrustum(Camera.View * Camera.Projection);

            // Update Units
            Predicate <RTSUnit> fFVU = (u) => {
                return(frustum.Intersects(u.BBox));
            };

            foreach (var um in FriendlyUnitModels)
            {
                um.UpdateInstances(G, GameplayController.IsUnitDead, fFVU);
            }

            Predicate <RTSUnit> fNFVU = (u) => {
                Point up = HashHelper.Hash(u.GridPosition, cg.numCells, cg.size);
                if (cg.GetFogOfWar(up.X, up.Y, teamIndex) != FogOfWar.Active)
                {
                    return(false);
                }
                return(frustum.Intersects(u.BBox));
            };

            foreach (var um in NonFriendlyUnitModels)
            {
                um.UpdateInstances(G, GameplayController.IsUnitDead, UseFOW ? fNFVU : fFVU);
            }

            // Update Buildings
            Predicate <BoundingBox> fFVB = (b) => {
                return(frustum.Intersects(b));
            };

            foreach (var bm in FriendlyBuildingModels)
            {
                bm.UpdateInstances(G, fFVB);
            }
            foreach (var bm in NonFriendlyBuildingModels)
            {
                bm.UpdateInstances(G, fFVB);
            }
        }
        public void UpdateVisible(CollisionGrid cg)
        {
            // All Team Friendly Units Are Visible
            BoundingFrustum frustum = new BoundingFrustum(Camera.View * Camera.Projection);

            // Update Units
            Predicate<RTSUnit> fFVU = (u) => {
                return frustum.Intersects(u.BBox);
            };
            foreach(var um in FriendlyUnitModels)
                um.UpdateInstances(G, GameplayController.IsUnitDead, fFVU);

            Predicate<RTSUnit> fNFVU = (u) => {
                Point up = HashHelper.Hash(u.GridPosition, cg.numCells, cg.size);
                if(cg.GetFogOfWar(up.X, up.Y, teamIndex) != FogOfWar.Active)
                    return false;
                return frustum.Intersects(u.BBox);
            };
            foreach(var um in NonFriendlyUnitModels)
                um.UpdateInstances(G, GameplayController.IsUnitDead, UseFOW ? fNFVU : fFVU);

            // Update Buildings
            Predicate<BoundingBox> fFVB = (b) => {
                return frustum.Intersects(b);
            };
            foreach(var bm in FriendlyBuildingModels)
                bm.UpdateInstances(G, fFVB);
            foreach(var bm in NonFriendlyBuildingModels)
                bm.UpdateInstances(G, fFVB);
        }
Beispiel #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;
        }