Beispiel #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);
        }
Beispiel #2
0
        // Unit Addition And Removal
        public RTSUnit AddUnit(int type, Vector2 pos)
        {
            // Check For Unit Type Existence
            RTSUnitData data = Race.Units[type];

            if (data == null)
            {
                DevConsole.AddCommand("data null");
                return(null);
            }
            // Check For Unit Cap
            if (data.CurrentCount >= data.MaxCount)
            {
                return(null);
            }

            // Check For Population Cap
            if (data.PopulationCost + Population > PopulationCap)
            {
                return(null);
            }

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

            // Produce Unit
            Capital    -= data.CapitalCost;
            Population += data.PopulationCost;
            data.CurrentCount++;

            // Create Unit
            RTSUnit unit = new RTSUnit(this, data, pos);

            unit.ActionController    = data.DefaultActionController.CreateInstance <ACUnitActionController>();
            unit.AnimationController = data.DefaultAnimationController.CreateInstance <ACUnitAnimationController>();
            unit.MovementController  = data.DefaultMoveController.CreateInstance <ACUnitMovementController>();
            unit.CombatController    = data.DefaultCombatController.CreateInstance <ACUnitCombatController>();
            Units.Add(unit);
            if (OnUnitSpawn != null)
            {
                OnUnitSpawn(unit);
            }
            return(unit);
        }
Beispiel #3
0
        public static RTSUnitData Deserialize(BinaryReader s, GameState state, int index)
        {
            RTSUnitData data = new RTSUnitData(index);

            data.FriendlyName     = s.ReadString();
            data.InfoFile         = s.ReadString();
            data.Health           = s.ReadInt32();
            data.CapitalCost      = s.ReadInt32();
            data.PopulationCost   = s.ReadInt32();
            data.MaxCount         = s.ReadInt32();
            data.MovementSpeed    = s.ReadSingle();
            data.Impact           = s.ReadInt32();
            data.BuildTime        = s.ReadInt32();
            data.CarryingCapacity = s.ReadInt32();
            data.IsWorker         = s.ReadBoolean();
            BaseCombatData.Deserialize(s, data.BaseCombatData);
            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()];
            data.DefaultCombatController    = state.Scripts[s.ReadString()];
            data.DefaultMoveController      = state.Scripts[s.ReadString()];
            data.DefaultAnimationController = state.Scripts[s.ReadString()];
            return(data);
        }
Beispiel #4
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;
        }
Beispiel #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;
        }
Beispiel #6
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);
 }
        public static RTSUnitData 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
            RTSUnitData data = new RTSUnitData(index);
            ZXParser.ParseInto(mStr, data);
            data.InfoFile = PathHelper.GetRelativePath(infoFile.FullName);
            return data;
        }
Beispiel #8
0
        public static void Serialize(BinaryWriter s, RTSUnitData data)
        {
            s.Write(data.FriendlyName);
            s.Write(data.InfoFile);
            s.Write(data.Health);
            s.Write(data.CapitalCost);
            s.Write(data.PopulationCost);
            s.Write(data.MaxCount);
            s.Write(data.MovementSpeed);
            s.Write(data.Impact);
            s.Write(data.BuildTime);
            s.Write(data.CarryingCapacity);
            s.Write(data.IsWorker);
            BaseCombatData.Serialize(s, data.BaseCombatData);
            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);
            s.Write(data.DefaultCombatController.TypeName);
            s.Write(data.DefaultMoveController.TypeName);
            s.Write(data.DefaultAnimationController.TypeName);
        }
 public static void Serialize(BinaryWriter s, RTSUnitData data)
 {
     s.Write(data.FriendlyName);
     s.Write(data.InfoFile);
     s.Write(data.Health);
     s.Write(data.CapitalCost);
     s.Write(data.PopulationCost);
     s.Write(data.MaxCount);
     s.Write(data.MovementSpeed);
     s.Write(data.Impact);
     s.Write(data.BuildTime);
     s.Write(data.CarryingCapacity);
     s.Write(data.IsWorker);
     BaseCombatData.Serialize(s, data.BaseCombatData);
     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);
     s.Write(data.DefaultCombatController.TypeName);
     s.Write(data.DefaultMoveController.TypeName);
     s.Write(data.DefaultAnimationController.TypeName);
 }
Beispiel #10
0
 public static RTSUnitData Deserialize(BinaryReader s, GameState state, int index)
 {
     RTSUnitData data = new RTSUnitData(index);
     data.FriendlyName = s.ReadString();
     data.InfoFile = s.ReadString();
     data.Health = s.ReadInt32();
     data.CapitalCost = s.ReadInt32();
     data.PopulationCost = s.ReadInt32();
     data.MaxCount = s.ReadInt32();
     data.MovementSpeed = s.ReadSingle();
     data.Impact = s.ReadInt32();
     data.BuildTime = s.ReadInt32();
     data.CarryingCapacity = s.ReadInt32();
     data.IsWorker = s.ReadBoolean();
     BaseCombatData.Deserialize(s, data.BaseCombatData);
     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()];
     data.DefaultCombatController = state.Scripts[s.ReadString()];
     data.DefaultMoveController = state.Scripts[s.ReadString()];
     data.DefaultAnimationController = state.Scripts[s.ReadString()];
     return data;
 }