RTSEngine.Data.Team.RTSUnit.Deserialize C# (CSharp) Method

Deserialize() public static method

public static Deserialize ( BinaryReader s, RTSTeam team, int &target ) : RTSUnit
s System.IO.BinaryReader
team RTSTeam
target int
return RTSUnit
        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;
        }

Usage Example

Beispiel #1
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);
        }