Example #1
0
        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);
        }
Example #2
0
        public EnemyBuildingUpdater(GameState s, int tIndex, ViewedBuilding _vb, RTSBuilding b)
            : base(1)
        {
            state     = s;
            teamIndex = tIndex;
            Added     = false;
            isDead    = false;
            vb        = _vb;
            building  = b;

            if (b != null)
            {
                b.OnDestruction += OnBuildingDeath;
            }
            else
            {
                isDead = true;
            }

            RTSBuildingData data = state.teams[vb.Team].Race.Buildings[vb.Type];

            grids = new Point[data.GridSize.X * data.GridSize.Y];
            Point p  = vb.CellPoint;
            int   pi = 0;

            for (int y = 0; y < data.GridSize.Y; y++)
            {
                for (int x = 0; x < data.GridSize.X; x++)
                {
                    grids[pi++] = new Point(p.X + x, p.Y + y);
                }
            }
        }
        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 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;
            }
        }
        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;
                }
            }
        }