Exemplo n.º 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);
        }
Exemplo n.º 2
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.º 3
0
        public static RTSUnitModel ParseModel(RTSRenderer renderer, FileInfo infoFile, RTSRace race)
        {
            // Check File Existence
            if(infoFile == null || !infoFile.Exists) return null;

            ZXParser.SetEnvironment("FILEROOTDIR", infoFile.Directory.FullName);
            ZXParser.SetEnvironment("RENDERER", renderer);
            ZXParser.SetEnvironment("RACE", race);
            RTSUnitViewData vd = ZXParser.ParseFile(infoFile.FullName, typeof(RTSUnitViewData)) as RTSUnitViewData;
            return vd.View;
        }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
        public RTSTeam(int i, int t)
        {
            Index = i;
            ColorScheme = RTSColorScheme.Default;
            Type = t;

            // Teams Starts Out Empty
            Race = new RTSRace();
            units = new List<RTSUnit>();
            squads = new List<RTSSquad>();
            buildings = new List<RTSBuilding>();
            ViewedEnemyBuildings = new List<ViewedBuilding>();
            Capital = 0;
            Population = 0;
            PopulationCap = 0;

            // No Input Is Available For The Team Yet
            Input = null;
        }
Exemplo n.º 6
0
        public RTSTeam(int i, int t)
        {
            Index       = i;
            ColorScheme = RTSColorScheme.Default;
            Type        = t;

            // Teams Starts Out Empty
            Race                 = new RTSRace();
            units                = new List <RTSUnit>();
            squads               = new List <RTSSquad>();
            buildings            = new List <RTSBuilding>();
            ViewedEnemyBuildings = new List <ViewedBuilding>();
            Capital              = 0;
            Population           = 0;
            PopulationCap        = 0;

            // No Input Is Available For The Team Yet
            Input = null;
        }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
0
        public static RTSRace Parse(FileInfo infoFile, Dictionary<string, ReflectedScript> scripts)
        {
            // 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", scripts);

            // Read Data
            RTSRace data = new RTSRace();
            ZXParser.ParseInto(mStr, data);
            data.InfoFile = new FileInfo(PathHelper.GetRelativePath(infoFile.FullName));
            data.UpdateActiveUnits();
            data.UpdateActiveBuildings();
            return data;
        }
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);
        }