Exemplo n.º 1
0
 public static void Serialize(BinaryWriter s, RTSTeam team)
 {
     s.Write(team.Type);
     RTSRace.Serialize(s, team.Race);
     if (team.Input != null)
     {
         s.Write(true);
         s.Write(ReflectedScript.GetKey(team.Input));
         team.Input.Serialize(s);
     }
     else
     {
         s.Write(false);
     }
     s.Write(team.ColorScheme.Name);
     s.Write(team.ColorScheme.Primary);
     s.Write(team.ColorScheme.Secondary);
     s.Write(team.ColorScheme.Tertiary);
     s.Write(team.Buildings.Count);
     foreach (var building in team.Buildings)
     {
         RTSBuilding.Serialize(s, building);
     }
     s.Write(team.Units.Count);
     foreach (var unit in team.Units)
     {
         RTSUnit.Serialize(s, unit);
     }
     s.Write(team.Squads.Count);
     foreach (var squad in team.Squads)
     {
         RTSSquad.Serialize(s, squad);
     }
 }
Exemplo n.º 2
0
 public void Build(RTSTeam team)
 {
     string[] vText = new string[team.Race.ActiveBuildings.Length];
     buildings = new Dictionary<string, RTSBuildingData>();
     for(int i = 0; i < vText.Length; i++) {
         var bd = team.Race.ActiveBuildings[i];
         buildings.Add(bd.FriendlyName, bd);
         vText[i] = bd.FriendlyName;
     }
     Array.Sort(vText);
     Menu.Build(vText);
 }
Exemplo n.º 3
0
        public override void Load(GameState s, DirectoryInfo mapDir)
        {
            // Give The Player Team Starting Capital
            pTeam = null;
            for(int i = 0; i < s.activeTeams.Length; i++) {
                var at = s.activeTeams[i];
                if(pTeam == null && at.Team.Type == RTSInputType.Player) {
                    pTeam = at.Team;
                    pTeam.Input.AddEvent(new CapitalEvent(pTeam.Index, 1000));
                    pTeam.PopulationCap = 100;
                }
            }

            float[] heights = new float[s.CGrid.numCells.X * s.CGrid.numCells.Y];
            Vector2[] p = new Vector2[heights.Length];
            for(int y = 0, i = 0; y < s.CGrid.numCells.Y; y++) {
                for(int x = 0; x < s.CGrid.numCells.X; x++) {
                    p[i] = new Vector2(x + 0.5f, y + 0.5f) * s.CGrid.cellSize;
                    heights[i] = s.CGrid.HeightAt(p[i]);
                    i++;
                }
            }
            Array.Sort(heights, p, 0, heights.Length);
            int cS = 1, cE = 1;
            while(cS < heights.Length && heights[cS] == heights[0])
                cS++;
            while(cE < heights.Length && heights[heights.Length - 1 - cE] == heights[heights.Length - 1])
                cE++;
            Random r = new Random();
            Vector2 spawnPos = p[r.Next(cS)];
            int ti = heights.Length - 1 - r.Next(cE);
            targetHeight = heights[ti] - 0.5f;
            fireLocation = new Vector3(p[ti].X, targetHeight, p[ti].Y);

            pTeam.Input.AddEvent(new SpawnUnitEvent(pTeam.Index, 0, spawnPos));
            pTeam.Input.AddEvent(new SpawnUnitEvent(pTeam.Index, 0, spawnPos));
            pTeam.Input.AddEvent(new SpawnUnitEvent(pTeam.Index, 0, spawnPos));
            pTeam.Input.AddEvent(new SpawnUnitEvent(pTeam.Index, 0, spawnPos));
            DevConsole.AddCommand("franz ferdinand");
            pTeam.Input.OnNewSelection += (ic, ns) => {
                if(ns.Count < 1) return;
                s.SendPopup(@"Packs\presets\Tutorial0\2.png", new Rectangle(10, 60, 400, 300));
                System.Threading.Interlocked.Exchange(ref state, 3);
                s.AddParticle(new AlertParticle(fireLocation, 2, Color.Transparent, fireLocation + Vector3.Up * 3, 1, Color.OrangeRed, s.TotalGameTime, 4f));
            };
            state = 0;
        }
Exemplo n.º 4
0
        public static RTSSquad Deserialize(BinaryReader s, RTSTeam team, out List <int> units)
        {
            RTSSquad squad = team.AddSquad();
            int      c     = s.ReadInt32();

            units = new List <int>();
            for (int i = 0; i < c; i++)
            {
                units.Add(s.ReadInt32());
            }
            squad.gridPos = s.ReadVector2();
            if (s.ReadBoolean())
            {
                if (squad.ActionController != null)
                {
                    squad.ActionController.Deserialize(s);
                }
            }
            else
            {
                squad.ActionController = null;
            }
            if (s.ReadBoolean())
            {
                if (squad.MovementController != null)
                {
                    squad.MovementController.Deserialize(s);
                }
            }
            else
            {
                squad.MovementController = null;
            }
            if (s.ReadBoolean())
            {
                if (squad.TargetingController != null)
                {
                    squad.TargetingController.Deserialize(s);
                }
            }
            else
            {
                squad.TargetingController = null;
            }
            return(squad);
        }
Exemplo n.º 5
0
        // Creates a New RTSUnitInstance on the Given Team with the Given Data at the Given Position
        public RTSUnit(RTSTeam team, RTSUnitData data, Vector2 position)
        {
            // Identification
            UUID    = UUIDGenerator.GetUUID();
            Team    = team;
            Squad   = null;
            gridPos = position;

            // Set From Common Data
            Data   = data;
            Health = Data.Health;

            // Default Information
            height             = 0;
            ViewDirection      = Vector2.UnitX;
            CollisionGeometry  = Data.ICollidableShape.Clone() as ICollidable;
            MovementMultiplier = 1f;
            Resources          = 0;
        }
Exemplo n.º 6
0
        // Creates a New RTSUnitInstance on the Given Team with the Given Data at the Given Position
        public RTSUnit(RTSTeam team, RTSUnitData data, Vector2 position)
        {
            // Identification
            UUID = UUIDGenerator.GetUUID();
            Team = team;
            Squad = null;
            gridPos = position;

            // Set From Common Data
            Data = data;
            Health = Data.Health;

            // Default Information
            height = 0;
            ViewDirection = Vector2.UnitX;
            CollisionGeometry = Data.ICollidableShape.Clone() as ICollidable;
            MovementMultiplier = 1f;
            Resources = 0;
        }
Exemplo n.º 7
0
        // Constructor
        public RTSBuilding(RTSTeam team, RTSBuildingData data, Vector2 position)
        {
            // Identification
            UUID       = UUIDGenerator.GetUUID();
            Team       = team;
            gridPos    = position;
            viewedInfo = new BitArray(GameState.MAX_PLAYERS);
            viewedInfo.SetAll(false);

            Data                      = data;
            gridPos.X                += (Data.GridSize.X - 1);
            gridPos.Y                += (Data.GridSize.Y - 1);
            height                    = 0;
            Health                    = Data.Health;
            bAmount                   = Data.BuildAmount;
            CollisionGeometry         = Data.ICollidableShape.Clone() as ICollidable;
            ViewDirection             = Vector2.UnitX;
            CollisionGeometry.Center += GridPosition;
            bControllers              = new List <ACBuildingButtonController>();
        }
Exemplo n.º 8
0
        // Constructor
        public RTSBuilding(RTSTeam team, RTSBuildingData data, Vector2 position)
        {
            // Identification
            UUID = UUIDGenerator.GetUUID();
            Team = team;
            gridPos = position;
            viewedInfo = new BitArray(GameState.MAX_PLAYERS);
            viewedInfo.SetAll(false);

            Data = data;
            gridPos.X += (Data.GridSize.X - 1);
            gridPos.Y += (Data.GridSize.Y - 1);
            height = 0;
            Health = Data.Health;
            bAmount = Data.BuildAmount;
            CollisionGeometry = Data.ICollidableShape.Clone() as ICollidable;
            ViewDirection = Vector2.UnitX;
            CollisionGeometry.Center += GridPosition;
            bControllers = new List<ACBuildingButtonController>();
        }
Exemplo n.º 9
0
        public static RTSBuilding Deserialize(BinaryReader s, RTSTeam team, out int?target)
        {
            int         type = s.ReadInt32();
            RTSBuilding e    = team.AddBuilding(type, Vector2.Zero);

            if (e == null)
            {
                throw new Exception("Could Not Create A Building That Was Previously Created");
            }
            e.UUID          = s.ReadInt32();
            e.State         = s.ReadInt32();
            e.ViewDirection = s.ReadVector2();
            e.GridPosition  = s.ReadVector2();
            e.Height        = s.ReadSingle();
            if (s.ReadBoolean())
            {
                target = s.ReadInt32();
            }
            else
            {
                target = null;
            }
            e.Health = s.ReadInt32();
            for (int i = 0; i < GameState.MAX_PLAYERS; i++)
            {
                e.viewedInfo.Set(i, s.ReadBoolean());
            }
            if (s.ReadBoolean())
            {
                if (e.ActionController != null)
                {
                    e.ActionController.Deserialize(s);
                }
            }
            else
            {
                e.ActionController = null;
            }
            return(e);
        }
Exemplo n.º 10
0
        public static RTSTeam Deserialize(BinaryReader s, int index, GameState state)
        {
            int t = s.ReadInt32();
            RTSTeam team = new RTSTeam(index, t);
            team.Race = RTSRace.Deserialize(s, state);
            if(s.ReadBoolean()) {
                string it = s.ReadString();
                team.Input = state.Scripts[it].CreateInstance<ACInputController>();
                team.Input.Deserialize(s);
                team.Input.Init(state, index, null);
            }

            RTSColorScheme scheme = new RTSColorScheme();
            scheme.Name = s.ReadString();
            scheme.Primary = s.ReadVector3();
            scheme.Secondary = s.ReadVector3();
            scheme.Tertiary = s.ReadVector3();
            team.ColorScheme = scheme;

            int? target;
            var du = new Dictionary<int, RTSUnit>();
            List<int> su;

            int c = s.ReadInt32();
            RTSBuilding building;
            for(int i = 0; i < c; i++) {
                building = RTSBuilding.Deserialize(s, team, out target);
                team.buildings.Add(building);
                if(target.HasValue) {
                    // TODO: Add A Target Binding
                }
                state.CGrid.Add(building);
            }

            c = s.ReadInt32();
            RTSUnit unit;
            for(int i = 0; i < c; i++) {
                unit = RTSUnit.Deserialize(s, team, out target);
                du.Add(unit.UUID, unit);
                team.units.Add(unit);
                if(target.HasValue) {
                    // TODO: Add A Target Binding
                }
            }

            c = s.ReadInt32();
            RTSSquad squad;
            for(int i = 0; i < c; i++) {
                squad = RTSSquad.Deserialize(s, team, out su);
                team.squads.Add(squad);
                foreach(int uuid in su) {
                    if(du.TryGetValue(uuid, out unit)) {
                        squad.Add(unit);
                    }
                    else {
                        throw new Exception("Could Not Find A Unit With The Specified UUID");
                    }
                }
            }
            return team;
        }
Exemplo n.º 11
0
 public static RTSUnit Deserialize(BinaryReader s, RTSTeam team, out int? target)
 {
     int type = s.ReadInt32();
     RTSUnit e = team.AddUnit(type, Vector2.Zero);
     if(e == null) throw new Exception("Could Not Create A Unit That Was Previously Created");
     e.UUID = s.ReadInt32();
     e.State = s.ReadInt32();
     e.ViewDirection = s.ReadVector2();
     e.GridPosition = s.ReadVector2();
     e.Height = s.ReadSingle();
     if(s.ReadBoolean()) {
         target = s.ReadInt32();
     }
     else {
         target = null;
     }
     e.Health = s.ReadInt32();
     e.MovementMultiplier = s.ReadSingle();
     e.Resources = s.ReadInt32();
     if(s.ReadBoolean()) {
         if(e.ActionController != null) e.ActionController.Deserialize(s);
     }
     else {
         e.ActionController = null;
     }
     if(s.ReadBoolean()) {
         if(e.CombatController != null) e.CombatController.Deserialize(s);
     }
     else {
         e.CombatController = null;
     }
     if(s.ReadBoolean()) {
         if(e.MovementController != null) e.MovementController.Deserialize(s);
     }
     else {
         e.MovementController = null;
     }
     if(s.ReadBoolean()) {
         if(e.AnimationController != null) e.AnimationController.Deserialize(s);
     }
     else {
         e.AnimationController = null;
     }
     return e;
 }
Exemplo n.º 12
0
 public IndexedTeam(int i, RTSTeam t)
 {
     Index = i;
     Team = t;
 }
Exemplo n.º 13
0
 public static RTSBuilding Deserialize(BinaryReader s, RTSTeam team, out int? target)
 {
     int type = s.ReadInt32();
     RTSBuilding e = team.AddBuilding(type, Vector2.Zero);
     if(e == null) throw new Exception("Could Not Create A Building That Was Previously Created");
     e.UUID = s.ReadInt32();
     e.State = s.ReadInt32();
     e.ViewDirection = s.ReadVector2();
     e.GridPosition = s.ReadVector2();
     e.Height = s.ReadSingle();
     if(s.ReadBoolean()) {
         target = s.ReadInt32();
     }
     else {
         target = null;
     }
     e.Health = s.ReadInt32();
     for(int i = 0; i < GameState.MAX_PLAYERS; i++) {
         e.viewedInfo.Set(i, s.ReadBoolean());
     }
     if(s.ReadBoolean()) {
         if(e.ActionController != null) e.ActionController.Deserialize(s);
     }
     else {
         e.ActionController = null;
     }
     return e;
 }
Exemplo n.º 14
0
 public RTSSquad(RTSTeam team)
 {
     Team = team;
     units = new List<RTSUnit>();
 }
Exemplo n.º 15
0
 public static RTSSquad Deserialize(BinaryReader s, RTSTeam team, out List<int> units)
 {
     RTSSquad squad = team.AddSquad();
     int c = s.ReadInt32();
     units = new List<int>();
     for(int i = 0; i < c; i++) {
         units.Add(s.ReadInt32());
     }
     squad.gridPos = s.ReadVector2();
     if(s.ReadBoolean()) {
         if(squad.ActionController != null) squad.ActionController.Deserialize(s);
     }
     else {
         squad.ActionController = null;
     }
     if(s.ReadBoolean()) {
         if(squad.MovementController != null) squad.MovementController.Deserialize(s);
     }
     else {
         squad.MovementController = null;
     }
     if(s.ReadBoolean()) {
         if(squad.TargetingController != null) squad.TargetingController.Deserialize(s);
     }
     else {
         squad.TargetingController = null;
     }
     return squad;
 }
Exemplo n.º 16
0
 public ScanTask(int s, int e, CollisionGrid g, RTSTeam t, Queue<SeenEntity> q)
     : base(1)
 {
     xs = s;
     xe = e;
     cg = g;
     team = t;
     queue = q;
     lastAdded = 0;
 }
Exemplo n.º 17
0
 public static void Serialize(BinaryWriter s, RTSTeam team)
 {
     s.Write(team.Type);
     RTSRace.Serialize(s, team.Race);
     if(team.Input != null) {
         s.Write(true);
         s.Write(ReflectedScript.GetKey(team.Input));
         team.Input.Serialize(s);
     }
     else {
         s.Write(false);
     }
     s.Write(team.ColorScheme.Name);
     s.Write(team.ColorScheme.Primary);
     s.Write(team.ColorScheme.Secondary);
     s.Write(team.ColorScheme.Tertiary);
     s.Write(team.Buildings.Count);
     foreach(var building in team.Buildings) {
         RTSBuilding.Serialize(s, building);
     }
     s.Write(team.Units.Count);
     foreach(var unit in team.Units) {
         RTSUnit.Serialize(s, unit);
     }
     s.Write(team.Squads.Count);
     foreach(var squad in team.Squads) {
         RTSSquad.Serialize(s, squad);
     }
 }
Exemplo n.º 18
0
        public void Hook(RTSRenderer renderer, GameState s, int ti, int fti, int building)
        {
            // Filter For Unit Types
            RTSTeam team = s.teams[ti];
            Data = team.Race.Buildings[building];
            fTeam = s.teams[fti];
            eTeamIndex = ti;
            fTeamIndex = fti;
            bType = building;

            // Create Instance Buffer
            visible = new List<VisibleBuilding>();
            instVerts = new VertexRTSAnimInst[Data.MaxCount];

            for(int i = 0; i < instVerts.Length; i++)
                instVerts[i] = new VertexRTSAnimInst(Matrix.Identity, 1);
            dvbInstances = renderer.CreateDynamicVertexBuffer(VertexRTSAnimInst.Declaration, instVerts.Length, BufferUsage.WriteOnly);
            dvbInstances.SetData(instVerts);
            dvbInstances.ContentLost += (sender, args) => { rebuildDVB = true; };
            rebuildDVB = false;
        }
Exemplo n.º 19
0
 public void SetTeam(RTSTeam team)
 {
     if(BuildingPanel != null) {
         BuildingPanel.Build(team);
         BuildingPanel.Hook();
     }
 }
Exemplo n.º 20
0
        public static RTSUnit Deserialize(BinaryReader s, RTSTeam team, out int?target)
        {
            int     type = s.ReadInt32();
            RTSUnit e    = team.AddUnit(type, Vector2.Zero);

            if (e == null)
            {
                throw new Exception("Could Not Create A Unit That Was Previously Created");
            }
            e.UUID          = s.ReadInt32();
            e.State         = s.ReadInt32();
            e.ViewDirection = s.ReadVector2();
            e.GridPosition  = s.ReadVector2();
            e.Height        = s.ReadSingle();
            if (s.ReadBoolean())
            {
                target = s.ReadInt32();
            }
            else
            {
                target = null;
            }
            e.Health             = s.ReadInt32();
            e.MovementMultiplier = s.ReadSingle();
            e.Resources          = s.ReadInt32();
            if (s.ReadBoolean())
            {
                if (e.ActionController != null)
                {
                    e.ActionController.Deserialize(s);
                }
            }
            else
            {
                e.ActionController = null;
            }
            if (s.ReadBoolean())
            {
                if (e.CombatController != null)
                {
                    e.CombatController.Deserialize(s);
                }
            }
            else
            {
                e.CombatController = null;
            }
            if (s.ReadBoolean())
            {
                if (e.MovementController != null)
                {
                    e.MovementController.Deserialize(s);
                }
            }
            else
            {
                e.MovementController = null;
            }
            if (s.ReadBoolean())
            {
                if (e.AnimationController != null)
                {
                    e.AnimationController.Deserialize(s);
                }
            }
            else
            {
                e.AnimationController = null;
            }
            return(e);
        }
Exemplo n.º 21
0
 public RTSSquad(RTSTeam team)
 {
     Team  = team;
     units = new List <RTSUnit>();
 }
Exemplo n.º 22
0
        public override void Init(GameState s, int ti, object args)
        {
            base.Init(s, ti, args);
            Team.Capital = int.MaxValue/2;
            Team.PopulationCap = int.MaxValue/2;
            Team.OnBuildingSpawn += OnBuildingSpawn;
            Team.OnUnitSpawn += OnUnitSpawn;
            random = new Random();
            spawnCap = 0;
            unitSpawnP = new int[] { 33, 33, 34 };
            barracksControllers = new List<BarracksController>();
            squads = new List<List<IEntity>>();
            numActive = 0;
            timeElapsed = 0;
            level = AggressionLevel.None;
            dt = 10; //5

            foreach (var b in Team.Buildings) {
                DevConsole.AddCommand("added barracks");
                barracksControllers.Add(new BarracksController(this, b));
            }

            for (int i = 0; i < s.activeTeams.Length; i++) {
                if (s.activeTeams[i].Team.Input.Type == RTSInputType.Player)
                    playerIndex = s.activeTeams[i].Team.Index;
            }
            player = s.teams[playerIndex];

            thread = new Thread(WorkThread);
            thread.IsBackground = true;
            running = true;
            paused = true;
        }
Exemplo n.º 23
0
 private static void BuildTeams(GameState state, EngineLoadData eld, Dictionary<string, FileInfo> races)
 {
     RTSTeam team;
     for(int i = 0; i < eld.Teams.Length; i++) {
         TeamInitOption res = eld.Teams[i];
         if(res.InputType == RTSInputType.None)
             continue;
         team = new RTSTeam(i, res.InputType);
         team.ColorScheme = res.Colors;
         team.Race = RTSRaceParser.Parse(races[res.Race], state.Scripts);
         state.teams[i] = team;
     }
 }
Exemplo n.º 24
0
        public static RTSTeam Deserialize(BinaryReader s, int index, GameState state)
        {
            int     t    = s.ReadInt32();
            RTSTeam team = new RTSTeam(index, t);

            team.Race = RTSRace.Deserialize(s, state);
            if (s.ReadBoolean())
            {
                string it = s.ReadString();
                team.Input = state.Scripts[it].CreateInstance <ACInputController>();
                team.Input.Deserialize(s);
                team.Input.Init(state, index, null);
            }

            RTSColorScheme scheme = new RTSColorScheme();

            scheme.Name      = s.ReadString();
            scheme.Primary   = s.ReadVector3();
            scheme.Secondary = s.ReadVector3();
            scheme.Tertiary  = s.ReadVector3();
            team.ColorScheme = scheme;

            int?       target;
            var        du = new Dictionary <int, RTSUnit>();
            List <int> su;

            int         c = s.ReadInt32();
            RTSBuilding building;

            for (int i = 0; i < c; i++)
            {
                building = RTSBuilding.Deserialize(s, team, out target);
                team.buildings.Add(building);
                if (target.HasValue)
                {
                    // TODO: Add A Target Binding
                }
                state.CGrid.Add(building);
            }

            c = s.ReadInt32();
            RTSUnit unit;

            for (int i = 0; i < c; i++)
            {
                unit = RTSUnit.Deserialize(s, team, out target);
                du.Add(unit.UUID, unit);
                team.units.Add(unit);
                if (target.HasValue)
                {
                    // TODO: Add A Target Binding
                }
            }

            c = s.ReadInt32();
            RTSSquad squad;

            for (int i = 0; i < c; i++)
            {
                squad = RTSSquad.Deserialize(s, team, out su);
                team.squads.Add(squad);
                foreach (int uuid in su)
                {
                    if (du.TryGetValue(uuid, out unit))
                    {
                        squad.Add(unit);
                    }
                    else
                    {
                        throw new Exception("Could Not Find A Unit With The Specified UUID");
                    }
                }
            }
            return(team);
        }