示例#1
0
        public static RTSRace Deserialize(BinaryReader s, GameState state)
        {
            RTSRace race = new RTSRace();

            race.FriendlyName = s.ReadString();
            int c = s.ReadInt32();

            for (int i = 0; i < c; i++)
            {
                int ui = s.ReadInt32();
                race.Units[ui] = RTSUnitData.Deserialize(s, state, ui);
            }
            race.UpdateActiveUnits();
            c = s.ReadInt32();
            for (int i = 0; i < c; i++)
            {
                int bi = s.ReadInt32();
                race.Buildings[bi] = RTSBuildingData.Deserialize(s, state, bi);
            }
            race.UpdateActiveBuildings();
            race.SCAction    = state.Scripts[s.ReadString()];
            race.SCMovement  = state.Scripts[s.ReadString()];
            race.SCTargeting = state.Scripts[s.ReadString()];
            return(race);
        }
示例#2
0
        public static void Serialize(BinaryWriter s, RTSBuildingData data)
        {
            s.Write(data.FriendlyName);
            s.Write(data.InfoFile);
            s.Write(data.Health);
            s.Write(data.CapitalCost);
            s.Write(data.PopCapChange);
            s.Write(data.MaxCount);
            s.Write(data.IsResource);
            s.Write(data.Impact);
            s.Write(data.BuildAmount);
            s.Write(data.Depositable);
            s.Write(data.SightRadius);
            s.Write(data.GridSize);
            s.Write((int)data.ICollidableShape.CollisionType);
            s.Write(data.ICollidableShape.Center);
            s.Write(data.ICollidableShape.IsStatic);
            switch (data.ICollidableShape.CollisionType)
            {
            case CollisionType.Circle:
                var cc = data.ICollidableShape as CollisionCircle;
                s.Write(cc.Radius);
                break;

            case CollisionType.Rectangle:
                var cr = data.ICollidableShape as CollisionRect;
                s.Write(cr.Width);
                s.Write(cr.Depth);
                break;
            }
            s.Write(data.BBox.Min);
            s.Write(data.BBox.Max);
            s.Write(data.DefaultActionController.TypeName);
        }
示例#3
0
 public static void Serialize(BinaryWriter s, RTSRace race)
 {
     s.Write(race.FriendlyName);
     s.Write(race.ActiveUnits.Length);
     foreach (var d in race.ActiveUnits)
     {
         s.Write(d.Index);
         RTSUnitData.Serialize(s, d);
     }
     s.Write(race.ActiveBuildings.Length);
     foreach (var d in race.ActiveBuildings)
     {
         s.Write(d.Index);
         RTSBuildingData.Serialize(s, d);
     }
     s.Write(race.SCAction.TypeName);
     s.Write(race.SCMovement.TypeName);
     s.Write(race.SCTargeting.TypeName);
 }
示例#4
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>();
        }
示例#5
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>();
        }
示例#6
0
        public static RTSBuildingData Deserialize(BinaryReader s, GameState state, int index)
        {
            RTSBuildingData data = new RTSBuildingData(index);

            data.FriendlyName = s.ReadString();
            data.InfoFile     = s.ReadString();
            data.Health       = s.ReadInt32();
            data.CapitalCost  = s.ReadInt32();
            data.PopCapChange = s.ReadInt32();
            data.MaxCount     = s.ReadInt32();
            data.IsResource   = s.ReadBoolean();
            data.Impact       = s.ReadInt32();
            data.BuildAmount  = s.ReadInt32();
            data.Depositable  = s.ReadBoolean();
            data.SightRadius  = s.ReadInt32();
            data.GridSize     = s.ReadPoint();
            CollisionType ct = (CollisionType)s.ReadInt32();
            Vector2       cc = s.ReadVector2();
            bool          cs = s.ReadBoolean();

            switch (ct)
            {
            case CollisionType.Circle:
                float cr = s.ReadSingle();
                data.ICollidableShape = new CollisionCircle(cr, cc, cs);
                break;

            case CollisionType.Rectangle:
                float cw = s.ReadSingle();
                float cd = s.ReadSingle();
                data.ICollidableShape = new CollisionRect(cw, cd, cc, cs);
                break;

            default:
                throw new Exception("Nonexistent Collision Type");
            }
            data.BBox.Min = s.ReadVector3();
            data.BBox.Max = s.ReadVector3();
            data.DefaultActionController = state.Scripts[s.ReadString()];
            return(data);
        }
示例#7
0
        // Building Addition And Removal
        public RTSBuilding AddBuilding(int type, Vector2 pos)
        {
            // Check For Building Type Existence
            RTSBuildingData data = Race.Buildings[type];

            if (data == null)
            {
                return(null);
            }

            // Check For Building Cap
            if (data.CurrentCount >= data.MaxCount)
            {
                return(null);
            }

            // Check For Capital Cost
            if (data.CapitalCost > Capital)
            {
                return(null);
            }

            // Produce Building
            Capital -= data.CapitalCost;
            data.CurrentCount++;

            RTSBuilding b = new RTSBuilding(this, data, pos);

            b.OnBuildingFinished += OnBuildingFinished;
            b.ActionController    = data.DefaultActionController.CreateInstance <ACBuildingActionController>();
            for (int i = 0; i < data.DefaultButtonControllers.Count; i++)
            {
                b.AddButton(data.DefaultButtonControllers[i].CreateInstance <ACBuildingButtonController>());
            }
            Buildings.Add(b);
            if (OnBuildingSpawn != null)
            {
                OnBuildingSpawn(b);
            }
            return(b);
        }
        public static RTSBuildingData ParseData(Dictionary<string, ReflectedScript> controllers, FileInfo infoFile, int index)
        {
            // Check File Existence
            if(infoFile == null || !infoFile.Exists) return null;

            // Read The Entire File
            string mStr;
            using(FileStream fs = File.OpenRead(infoFile.FullName)) {
                StreamReader s = new StreamReader(fs);
                mStr = s.ReadToEnd();
            }

            // Set Environment Variables
            ZXParser.SetEnvironment("FILEROOTDIR", infoFile.Directory.FullName);
            ZXParser.SetEnvironment("DICTSCRIPTS", controllers);

            // Read Data
            RTSBuildingData data = new RTSBuildingData(index);
            ZXParser.ParseInto(mStr, data);
            data.InfoFile = PathHelper.GetRelativePath(infoFile.FullName);
            return data;
        }
 public static RTSBuildingData Deserialize(BinaryReader s, GameState state, int index)
 {
     RTSBuildingData data = new RTSBuildingData(index);
     data.FriendlyName = s.ReadString();
     data.InfoFile = s.ReadString();
     data.Health = s.ReadInt32();
     data.CapitalCost = s.ReadInt32();
     data.PopCapChange = s.ReadInt32();
     data.MaxCount = s.ReadInt32();
     data.IsResource = s.ReadBoolean();
     data.Impact = s.ReadInt32();
     data.BuildAmount = s.ReadInt32();
     data.Depositable = s.ReadBoolean();
     data.SightRadius = s.ReadInt32();
     data.GridSize = s.ReadPoint();
     CollisionType ct = (CollisionType)s.ReadInt32();
     Vector2 cc = s.ReadVector2();
     bool cs = s.ReadBoolean();
     switch(ct) {
         case CollisionType.Circle:
             float cr = s.ReadSingle();
             data.ICollidableShape = new CollisionCircle(cr, cc, cs);
             break;
         case CollisionType.Rectangle:
             float cw = s.ReadSingle();
             float cd = s.ReadSingle();
             data.ICollidableShape = new CollisionRect(cw, cd, cc, cs);
             break;
         default:
             throw new Exception("Nonexistent Collision Type");
     }
     data.BBox.Min = s.ReadVector3();
     data.BBox.Max = s.ReadVector3();
     data.DefaultActionController = state.Scripts[s.ReadString()];
     return data;
 }
示例#10
0
 public static void Serialize(BinaryWriter s, RTSBuildingData data)
 {
     s.Write(data.FriendlyName);
     s.Write(data.InfoFile);
     s.Write(data.Health);
     s.Write(data.CapitalCost);
     s.Write(data.PopCapChange);
     s.Write(data.MaxCount);
     s.Write(data.IsResource);
     s.Write(data.Impact);
     s.Write(data.BuildAmount);
     s.Write(data.Depositable);
     s.Write(data.SightRadius);
     s.Write(data.GridSize);
     s.Write((int)data.ICollidableShape.CollisionType);
     s.Write(data.ICollidableShape.Center);
     s.Write(data.ICollidableShape.IsStatic);
     switch(data.ICollidableShape.CollisionType) {
         case CollisionType.Circle:
             var cc = data.ICollidableShape as CollisionCircle;
             s.Write(cc.Radius);
             break;
         case CollisionType.Rectangle:
             var cr = data.ICollidableShape as CollisionRect;
             s.Write(cr.Width);
             s.Write(cr.Depth);
             break;
     }
     s.Write(data.BBox.Min);
     s.Write(data.BBox.Max);
     s.Write(data.DefaultActionController.TypeName);
 }
 public void OnUIPress(Point p, MouseButton b)
 {
     Vector2 r = Vector2.Zero;
     if(UI.Minimap.WidgetBase.Inside(p.X, p.Y)) {
         if(!UI.Minimap.MapRect.Inside(p.X, p.Y, out r))
             return;
         // Use The Minimap
         Vector2 mapPos = r * GameState.CGrid.size;
         if(b == BUTTON_SELECT) {
             // Move To The Minimap Spot
             if(Camera == null) return;
             Camera.MoveTo(mapPos.X, mapPos.Y);
         }
         else if(b == BUTTON_ACTION) {
             // Try To Move Selected Units There
             if(selected.Count > 0)
                 AddEvent(new SetWayPointEvent(TeamIndex, mapPos));
         }
     }
     else if(UI.SelectionPanel.BackPanel.Inside(p.X, p.Y)) {
         var ug = UI.SelectionPanel.GetSelection(p.X, p.Y);
         if(ug != null) {
             AddEvent(new SelectEvent(TeamIndex, ug));
         }
     }
     else if(UI.BuildingPanel.Inside(p.X, p.Y)) {
         buildingToPlace = UI.BuildingPanel.GetSelection(p.X, p.Y);
     }
     else if(UI.BBPanel.BackPanel.Inside(p.X, p.Y)) {
         var bbs = UI.BBPanel.GetSelection(p.X, p.Y);
         if(bbs != null) {
             // Shift Clicking
             int c = isShiftPressed ? 5 : 1;
             for(int ci = 0; ci < c; ci++) {
                 for(int i = 0; i < bbs.Count; i++) {
                     bbs[i].OnClick();
                 }
             }
         }
     }
 }
        public void OnMousePress(Vector2 location, MouseButton b)
        {
            if(Camera == null) return;
            Camera.Controller.IsActive = false;

            Point pl = new Point((int)location.X, (int)location.Y);
            if(UI != null && UI.Inside(pl.X, pl.Y)) {
                // Check UI Actions
                OnUIPress(pl, b);
            }
            else {
                // Action In The World
                if(b == BUTTON_ACTION) {
                    if(Camera == null) return;
                    Ray ray = Camera.GetViewRay(location);

                    // Check Building Placement
                    if(buildingToPlace != null) {
                        ray.Position *= new Vector3(0.5f, 1f, 0.5f);
                        ray.Direction *= new Vector3(0.5f, 1f, 0.5f);
                        ray.Direction.Normalize();
                        var nvl = VRayHelper.GetOuter(ray, GameState.VoxState);
                        if(nvl.HasValue) {
                            Vector3 rh = new Vector3(
                                nvl.Value.RegionLoc.X * Region.WIDTH + nvl.Value.VoxelLoc.X,
                                nvl.Value.VoxelLoc.Y,
                                nvl.Value.RegionLoc.Y * Region.DEPTH + nvl.Value.VoxelLoc.Z
                                );
                            rh *= new Vector3(2f, 1f, 2f);
                            Point bp = HashHelper.Hash(new Vector2(rh.X, rh.Z), GameState.CGrid.numCells, GameState.CGrid.size);
                            AddEvent(new SpawnBuildingEvent(TeamIndex, buildingToPlace.Index, bp));
                            AddEvent(new ImpactEvent(TeamIndex, new Vector2(bp.X, bp.Y), buildingToPlace.Impact));
                        }
                        if(!isShiftPressed) buildingToPlace = null;
                        return;
                    }

                    // Get Ray From Mouse Position
                    IEntity se = SelectFromRay(ray);
                    if(se != null) {
                        // Use Entity As A Target
                        AddEvent(new SetTargetEvent(TeamIndex, se));
                    }
                    else if(!HasSelectedEnemy) {
                        // Add A Waypoint Event
                        ray.Position *= new Vector3(0.5f, 1f, 0.5f);
                        ray.Direction *= new Vector3(0.5f, 1f, 0.5f);
                        ray.Direction.Normalize();
                        var nvl = VRayHelper.GetOuter(ray, GameState.VoxState);
                        if(nvl.HasValue) {
                            Vector3 rh = new Vector3(
                                nvl.Value.RegionLoc.X * Region.WIDTH + nvl.Value.VoxelLoc.X,
                                nvl.Value.VoxelLoc.Y,
                                nvl.Value.RegionLoc.Y * Region.DEPTH + nvl.Value.VoxelLoc.Z
                                );
                            rh *= new Vector3(2f, 1f, 2f);
                            rh.X += 1f; rh.Z += 1f;
                            GameState.AddParticle(new AlertParticle(
                                rh, 1f, Color.Purple, rh + Vector3.Up * 2f, 0.2f, Color.Green, GameState.TotalGameTime, 4f
                                ));
                            AddEvent(new SetWayPointEvent(TeamIndex, new Vector2(rh.X, rh.Z)));
                        }
                    }
                }
                else if(b == BUTTON_SELECT) {
                    buildingToPlace = null;
                    useSelectRect = true;
                    selectionRectStart = location;
                }
            }
        }
 public void OnKeyPress(object sender, KeyEventArgs args)
 {
     switch(args.KeyCode) {
         case Keys.Delete:
             var arr = selected.ToArray();
             foreach(var e in arr)
                 AddEvent(new DamageEvent(TeamIndex, e.UUID, 1000000));
             break;
         case Keys.LeftShift:
         case Keys.RightShift:
             isShiftPressed = true;
             break;
         case Keys.Escape:
             buildingToPlace = null;
             break;
         case Keys.K:
             foreach(var entity in selected.ToArray()) {
                 RTSUnit unit = entity as RTSUnit;
                 if(unit != null) AddEvent (new SetOrdersEvent(TeamIndex, unit.UUID, BehaviorFSM.AttackMove, 3));
             }
             break;
         case Keys.M:
             foreach (var entity in selected.ToArray()) {
                 RTSUnit unit = entity as RTSUnit;
                 if (unit != null) AddEvent(new SetOrdersEvent(TeamIndex, unit.UUID, BehaviorFSM.JustMove, 3));
             }
             break;
     }
 }