Пример #1
0
        public EnemyBuildingUpdater(GameState s, int tIndex, ViewedBuilding _vb, RTSBuilding b)
            : base(1)
        {
            state     = s;
            teamIndex = tIndex;
            Added     = false;
            isDead    = false;
            vb        = _vb;
            building  = b;

            if (b != null)
            {
                b.OnDestruction += OnBuildingDeath;
            }
            else
            {
                isDead = true;
            }

            RTSBuildingData data = state.teams[vb.Team].Race.Buildings[vb.Type];

            grids = new Point[data.GridSize.X * data.GridSize.Y];
            Point p  = vb.CellPoint;
            int   pi = 0;

            for (int y = 0; y < data.GridSize.Y; y++)
            {
                for (int x = 0; x < data.GridSize.X; x++)
                {
                    grids[pi++] = new Point(p.X + x, p.Y + y);
                }
            }
        }
Пример #2
0
        public static EnemyBuildingUpdater Deserialize(BinaryReader s, GameState state)
        {
            int            ti = s.ReadInt32();
            ViewedBuilding vb = new ViewedBuilding();

            vb.Team          = s.ReadInt32();
            vb.Type          = s.ReadInt32();
            vb.CellPoint     = s.ReadPoint();
            vb.WorldPosition = s.ReadVector3();
            vb.ViewDirection = s.ReadVector2();
            int         uuid = s.ReadInt32();
            RTSBuilding b    = null;

            foreach (var building in state.teams[vb.Team].Buildings)
            {
                if (building.UUID == uuid)
                {
                    b = building;
                    break;
                }
            }
            EnemyBuildingUpdater ebu = new EnemyBuildingUpdater(state, ti, vb, b);

            ebu.Added  = s.ReadBoolean();
            ebu.isDead = s.ReadBoolean();
            if (ebu.Added)
            {
                state.teams[ebu.teamIndex].ViewedEnemyBuildings.Add(vb);
            }
            return(ebu);
        }
Пример #3
0
        private void AddTask(GameState s, RTSBuilding building, int fTeam, int type)
        {
            AddTask(s, building);
            ViewedBuilding vb = new ViewedBuilding();

            vb.Team          = fTeam;
            vb.Type          = type;
            vb.ViewDirection = building.ViewDirection;
            vb.WorldPosition = building.WorldPosition;
            vb.CellPoint     = HashHelper.Hash(building.GridPosition, s.CGrid.numCells, s.CGrid.size);
            for (int i = 0; i < s.teams.Length; i++)
            {
                if (i == fTeam || s.teams[i] == null)
                {
                    continue;
                }
                var ebu = new EnemyBuildingUpdater(s, i, vb, building);
                s.tbMemBuildings.AddTask(ebu);
            }
        }
Пример #4
0
        public void UpdateInstances(GraphicsDevice g, Predicate <BoundingBox> fVisible)
        {
            visible = new List <VisibleBuilding>();
            if (fTeamIndex == eTeamIndex)
            {
                // Always Show Friendly Buildings
                for (int i = 0; i < fTeam.Buildings.Count; i++)
                {
                    if (fTeam.Buildings[i].Data != Data)
                    {
                        continue;
                    }
                    if (fVisible(fTeam.Buildings[i].BBox))
                    {
                        VisibleBuilding vb = new VisibleBuilding();
                        vb.Position    = fTeam.Buildings[i].WorldPosition;
                        vb.View        = fTeam.Buildings[i].ViewDirection;
                        vb.BuildAmount = 1 - (float)fTeam.Buildings[i].BuildAmountLeft / (float)fTeam.Buildings[i].Data.BuildAmount;
                        if (vb.BuildAmount < 0.5)
                        {
                            visible.Add(vb);
                        }
                        else
                        {
                            visible.Add(vb);
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < fTeam.ViewedEnemyBuildings.Count; i++)
                {
                    ViewedBuilding bv = fTeam.ViewedEnemyBuildings[i];
                    if (bv.Team != eTeamIndex || bv.Type != bType)
                    {
                        continue;
                    }

                    BoundingBox bb = new BoundingBox(
                        Data.BBox.Min + bv.WorldPosition,
                        Data.BBox.Max + bv.WorldPosition
                        );
                    if (fVisible(bb))
                    {
                        VisibleBuilding vb = new VisibleBuilding();
                        vb.Position    = bv.WorldPosition;
                        vb.View        = bv.ViewDirection;
                        vb.BuildAmount = bv.BuildAmount;
                        visible.Add(vb);
                    }
                }
            }


            for (int i = 0; i < VisibleInstanceCount; i++)
            {
                instVerts[i].World =
                    Matrix.CreateRotationY(
                        (float)Math.Atan2(-visible[i].View.Y, visible[i].View.X)
                        ) *
                    Matrix.CreateTranslation(visible[i].Position)
                ;
                instVerts[i].AnimationFrame = visible[i].BuildAmount;
            }
            if (rebuildDVB)
            {
                dvbInstances              = new DynamicVertexBuffer(g, VertexRTSAnimInst.Declaration, instVerts.Length, BufferUsage.WriteOnly);
                dvbInstances.ContentLost += (s, a) => { rebuildDVB = true; };
            }
            dvbInstances.SetData(instVerts);
        }