Esempio n. 1
0
        public override void OnEntry(GameTime gameTime)
        {
            DevConsole.OnNewCommand += DevConsole_OnNewCommand;
            KeyboardEventDispatcher.OnKeyPressed += KeyboardEventDispatcher_OnKeyPressed;
            input.Refresh();
            sP.Hook();
            sS.Hook();
            sT.Hook();
            RendererInitArgs ria = ZXParser.ParseFile(@"Content\FX\RIA.txt", typeof(RendererInitArgs)) as RendererInitArgs;

            renderer = new RTSRenderer(game.Graphics, game.Content, ria, game.Window);

            // Rendering Effect
            fx = new RTSFXEntity(renderer.LoadEffect(FX_FILE_PATH));

            // Default Team
            sP.Color         = RTSColorScheme.Default.Primary;
            sS.Color         = RTSColorScheme.Default.Secondary;
            sT.Color         = RTSColorScheme.Default.Tertiary;
            colorScheme.Name = RTSColorScheme.Default.Name;

            // Create Camera
            camera       = new OrbitingCamera(Vector3.Zero, 4f, G.Viewport.AspectRatio);
            camera.Pitch = MathHelper.PiOver4;
            camera.Yaw   = 0;
            camera.FOV   = MathHelper.PiOver4;

            unitDataFiles = new List <FileInfo>();
            schemeFiles   = new List <FileInfo>();

            FindAllData();
            curUnit = 0;
        }
Esempio n. 2
0
        public static void SearchAllInitInfo(DirectoryInfo dir, Dictionary <string, FileInfo> races, Dictionary <string, RTSColorScheme> dictSchemes)
        {
            var files = dir.GetFiles();

            foreach (var file in files)
            {
                if (file.Extension.ToLower().EndsWith("race"))
                {
                    races.Add(RTSRaceParser.ParseName(file), file);
                }
                else if (file.Extension.ToLower().EndsWith("scheme"))
                {
                    object scheme = ZXParser.ParseFile(file.FullName, typeof(RTSColorScheme));
                    if (scheme != null)
                    {
                        var v = (RTSColorScheme)scheme;
                        dictSchemes.Add(v.Name, v);
                    }
                }
            }
            var dirs = dir.GetDirectories();

            foreach (var subDir in dirs)
            {
                SearchAllInitInfo(subDir, races, dictSchemes);
            }
        }
Esempio n. 3
0
        void DevConsole_OnNewCommand(string obj)
        {
            Match m;

            if ((m = rgxSetFile.Match(obj)).Success)
            {
                file = RegexHelper.ExtractFile(m);
            }
            else if ((m = rgxSetName.Match(obj)).Success)
            {
                name = RegexHelper.Extract(m);
            }
            else if ((m = rgxSave.Match(obj)).Success)
            {
                if (file == null)
                {
                    DevConsole.AddCommand("No File Specified");
                }
                else if (string.IsNullOrWhiteSpace(name))
                {
                    DevConsole.AddCommand("No Name Specified");
                }
                else
                {
                    using (var s = file.Create()) {
                        StreamWriter w = new StreamWriter(s);
                        w.WriteLine("NAME [{0}]", name);
                        w.WriteLine("PRIMARY [{0}, {1}, {2}]", colorScheme.Primary.X, colorScheme.Primary.Y, colorScheme.Primary.Z);
                        w.WriteLine("SECONDARY [{0}, {1}, {2}]", colorScheme.Secondary.X, colorScheme.Secondary.Y, colorScheme.Secondary.Z);
                        w.WriteLine("TERTIARY [{0}, {1}, {2}]", colorScheme.Tertiary.X, colorScheme.Tertiary.Y, colorScheme.Tertiary.Z);
                        w.Flush();
                    }
                }
            }
            else if ((m = rgxLoad.Match(obj)).Success)
            {
                if (file == null)
                {
                    DevConsole.AddCommand("No File Specified");
                }
                else if (!file.Exists)
                {
                    DevConsole.AddCommand("File Does Not Exist");
                }
                var cs = ZXParser.ParseFile(file.FullName, typeof(RTSColorScheme));
                if (cs == null)
                {
                    DevConsole.AddCommand("Incorrect File Format");
                }
                else
                {
                    colorScheme = (RTSColorScheme)cs;
                    name        = colorScheme.Name;
                    sP.Color    = colorScheme.Primary;
                    sS.Color    = colorScheme.Secondary;
                    sT.Color    = colorScheme.Tertiary;
                }
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public static TerrainData ParseData(FileInfo infoFile, List <ImpactRegion> regions)
        {
            // Check File Existence
            if (infoFile == null || !infoFile.Exists)
            {
                return(null);
            }

            ZXParser.SetEnvironment("FILEROOTDIR", infoFile.Directory.FullName);
            TerrainData mio = ZXParser.ParseFile(infoFile.FullName, typeof(TerrainData)) as TerrainData;

            mio.LGrid.InfoFile = PathHelper.GetRelativePath(infoFile.FullName);
            regions.AddRange(mio.Regions); // TODO: Remove
            return(mio);
        }
Esempio n. 6
0
        public override void Build()
        {
            gPresets      = new List <GamePreset>();
            inputTypes    = new string[GameState.MAX_PLAYERS];
            inputInitArgs = new object[GameState.MAX_PLAYERS];
            var di = new DirectoryInfo(PRESET_DIR);

            foreach (var fi in di.GetFiles())
            {
                if (!fi.Extension.EndsWith(@"game"))
                {
                    continue;
                }
                GamePreset gp = (GamePreset)ZXParser.ParseFile(fi.FullName, typeof(GamePreset));
                gPresets.Add(gp);
            }
        }
Esempio n. 7
0
        public override void Build()
        {
            uic = ZXParser.ParseFile(UIC_FILE, typeof(UICInduZtry)) as UICInduZtry;

            Random rColor = new Random();
            int    ci     = rColor.Next(0, uic.ColorCombos.Length);

            lBoltArgs.JagDisplacement = uic.Bolt.Width;
            lBoltArgs.LineMinLength   = uic.Bolt.MinLength;
            lBoltArgs.LineMaxLength   = uic.Bolt.MaxLength;
            lBoltArgs.Color           = uic.ColorCombos[ci].Foreground;

            lBranchArgs.JagDisplacement = uic.Branch.Width;
            lBranchArgs.LineMinLength   = uic.Branch.MinLength;
            lBranchArgs.LineMaxLength   = uic.Branch.MaxLength;
            lBranchArgs.BranchSlope     = uic.BranchingSlope;
            lBranchArgs.MinBounds       = Vector2.Zero;
            lBranchArgs.MaxBounds       = ViewSize;
            lBranchArgs.Color           = uic.ColorCombos[ci].Background;
        }
Esempio n. 8
0
        public RTSUI(RTSRenderer renderer, string uicFile, bool showBuildPanel)
        {
            uic = ZXParser.ParseFile(uicFile, typeof(UICRTS)) as UICRTS;

            SpriteFont font = renderer.LoadFont(uic.Font);

            wrButtonPanel = new WidgetRenderer(renderer.G, font);
            wrMain        = new WidgetRenderer(renderer.G, font);

            BuildBounds(renderer);
            BuildMinimap(renderer, uic.UICMinimap);
            BuildBBPanel(renderer);
            BuildBuildingPanel(showBuildPanel);
            BuildSelectionPanel(renderer);
            BuildUnitDataPanel(renderer);
            BuildBuildingDataPanel(renderer);
            BuildTeamDataPanel();
            AlertQueue = new RTSUIAlertQueue(wrMain, uic.UICAlertQueue);
            AlertQueue.WidgetBase.Parent = Minimap.WidgetBase;
            SelectionToggle = 0;
        }
Esempio n. 9
0
        //public SpriteFont CreateFont(string fontName, int size, int spacing = 0, bool useKerning = true, string style = "Regular", char defaultChar = '*', int cStart = 32, int cEnd = 126) {
        //    IDisposable disp;
        //    SpriteFont f = XNASpriteFont.Compile(G, fontName, size, out disp, spacing, useKerning, style, defaultChar, cStart, cEnd);
        //    toDispose.Add(disp);
        //    return f;
        //}
        //public SpriteFont CreateFont(string fontName, int size, out IDisposable disp, int spacing = 0, bool useKerning = true, string style = "Regular", char defaultChar = '*', int cStart = 32, int cEnd = 126) {
        //    SpriteFont f = XNASpriteFont.Compile(G, fontName, size, out disp, spacing, useKerning, style, defaultChar, cStart, cEnd);
        //    toDispose.Add(disp);
        //    return f;
        //}
        #endregion

        public void HookToGame(GameState state, int ti, Camera camera)
        {
            // Get The Team To Be Visualized
            teamIndex = ti;
            teamInput = state.teams[teamIndex].Input;
            SelectionCircleTexture = LoadTexture2D(@"Content\Textures\SelectionCircle.png");

            // Get The Camera
            Camera = camera;

            // Create The Map
            CreateVoxGeos(state.VoxState.World.Atlas);
            Map = new VoxMap(this, state.CGrid.numCells.X, state.CGrid.numCells.Y);
            // TODO: Parse This In
            VoxMapConfig vmc = new VoxMapConfig();

            vmc.VoxState  = state.VoxState;
            vmc.TexVoxMap = @"voxmap.png";
            vmc.RootPath  = state.LevelGrid.Directory.FullName;
            vmc.FXFile    = @"FX\Voxel";
            Map.Build(gManager, cManager, vmc);

            Camera.MoveTo(state.CGrid.size.X * 0.5f, state.CGrid.size.Y * 0.5f);
            fxMap.MapSize     = state.CGrid.size;
            pRenderer.MapSize = state.CGrid.size;

            // Hook FOW
            state.CGrid.OnFOWChange += OnFOWChange;
            Minimap.Hook(this, state, ti);


            // Load Particles
            // TODO: Config
            ParticleOptions pOpt = ZXParser.ParseFile(@"Content\FX\Particles\Particle.conf", typeof(ParticleOptions)) as ParticleOptions;

            pRenderer.Load(this, pOpt);

            // Load Team Visuals
            for (int i = 0; i < state.teams.Length; i++)
            {
                if (state.teams[i] == null)
                {
                    continue;
                }
                LoadTeamVisuals(state, i);
            }

            // Set FOW
            for (int y = 0; y < Map.FogOfWarTexture.Height; y++)
            {
                for (int x = 0; x < Map.FogOfWarTexture.Width; x++)
                {
                    switch (state.CGrid.GetFogOfWar(x, y, teamIndex))
                    {
                    case FogOfWar.Active:
                        Map.SetFOW(x, y, 1f);
                        break;

                    case FogOfWar.Passive:
                        Map.SetFOW(x, y, 0.5f);
                        break;

                    case FogOfWar.Nothing:
                        Map.SetFOW(x, y, 0f);
                        break;
                    }
                }
            }
        }
Esempio n. 10
0
        private void WorkThread()
        {
            try {
                // Start With Default Values
                isLoaded       = false;
                loadException  = null;
                LoadedRenderer = null;

                // Grab The Initialization Info
                loadData = game.LobbyScreen.InitInfo;

                // Build The Local Game State
                LoadedState = new GameState();
                if (LoadFile == null)
                {
                    GameEngine.BuildLocal(LoadedState, LoadData, new DirectoryInfo(@"Packs"), game.LobbyScreen.Races);
                }
                else
                {
                    GameEngine.Load(LoadedState, new DirectoryInfo(@"Packs"), LoadFile.FullName);
                }

                // Create The Input Controllers
                for (int ti = 0; ti < LoadedState.teams.Length; ti++)
                {
                    if (string.IsNullOrWhiteSpace(LoadData.Teams[ti].InputController))
                    {
                        continue;
                    }
                    GameEngine.SetInput(LoadedState, ti, LoadedState.Scripts[LoadData.Teams[ti].InputController].CreateInstance <ACInputController>());
                }


                // Create Camera
                LoadedCamera = new Camera(G.Viewport);
                LoadedCamera.Controller.Hook(game.Window);

                // Load The Renderer
                RendererInitArgs ria = ZXParser.ParseFile(@"Content\FX\RIA.txt", typeof(RendererInitArgs)) as RendererInitArgs;
                LoadedRenderer = new RTSRenderer(game.Graphics, game.Content, ria, game.Window);
                LoadedRenderer.HookToGame(LoadedState, 0, LoadedCamera);

                // Initialize Inputs
                int teami = -1;
                foreach (var t in LoadedState.teams)
                {
                    teami++;
                    if (t == null)
                    {
                        continue;
                    }

                    // Set Camera
                    var vInput = t.Input as IVisualInputController;
                    if (vInput != null)
                    {
                        vInput.Camera = LoadedCamera;
                    }

                    // Init
                    t.Input.Init(LoadedState, t.Index, loadData.Teams[teami].InputInitArgs);

                    // Build
                    if (vInput != null)
                    {
                        vInput.Build(LoadedRenderer);
                    }
                }

                // Create Gameplay
                LoadedGPlay = new GameplayController();
                GCInitArgs gca = new GCInitArgs()
                {
                    GameTypeScript = LoadData.GTController
                };
                LoadedGPlay.Init(LoadedState, gca);
            }
            catch (Exception e) {
                if (LoadedRenderer != null)
                {
                    LoadedRenderer.Dispose();
                }
                loadException = e;
            }
            isLoaded = true;
        }
Esempio n. 11
0
 public override void Build()
 {
     uic = ZXParser.ParseFile(UIC_FILE, typeof(UICCompanyLogo)) as UICCompanyLogo;
 }