Beispiel #1
0
        public DGRPImg(GraphicsDevice Device, Iff Parent, FileReader Reader, uint Version)
        {
            m_Graphics = Device;
            m_SBatch   = new SpriteBatch(m_Graphics);

            if (Version == 20000 || Version == 20001)
            {
                SpriteCount = Reader.ReadUShort();
                Direction   = (DirectionFlags)Reader.ReadByte();
                ZoomLevel   = Reader.ReadByte();

                for (int i = 0; i < SpriteCount; i++)
                {
                    SpriteInfo Info = new SpriteInfo(Reader, this, Version);
                    m_Sprites.Add(new DrawGroupSprite(Device, Info,
                                                      Parent.GetSprite((ushort)Info.SPRChunkID).GetFrame(Info.SPRFrameNum)));
                }
            }
            else
            {
                Direction   = (DirectionFlags)Reader.ReadUInt32();
                ZoomLevel   = Reader.ReadUInt32();
                SpriteCount = Reader.ReadUInt32();

                for (int i = 0; i < SpriteCount; i++)
                {
                    SpriteInfo Info = new SpriteInfo(Reader, this, Version);
                    m_Sprites.Add(new DrawGroupSprite(Device, Info,
                                                      Parent.GetSprite((ushort)Info.SPRChunkID).GetFrame(Info.SPRFrameNum)));
                }
            }
        }
Beispiel #2
0
        public void Set(DirectionFlags dir, Type type)
        {
            dirs |= dir;
            switch (dir)
            {
            case DirectionFlags.W:   edgeW = type;       break;

            case DirectionFlags.SW: edgeSW = type;       break;

            case DirectionFlags.S:   edgeS = type;       break;

            case DirectionFlags.SE: edgeSE = type;       break;

            case DirectionFlags.E:   edgeE = type;       break;

            case DirectionFlags.NE: edgeNE = type;       break;

            case DirectionFlags.N:   edgeN = type;       break;

            case DirectionFlags.NW: edgeNW = type;       break;

            case DirectionFlags.None:
            case DirectionFlags.All:
            default: Debug.LogWarning("Warning Called Set on GameVertex.Line with a dir not set to a single direction"); break;
            }
        }
Beispiel #3
0
 internal virtual void cheat(Game_Unit unit, DirectionFlags dir)
 {
     if (Cheat != null)
     {
         if (Cheat(unit, dir))
         {
             Global.game_system.play_se(System_Sounds.Menu_Move2);
         }
     }
 }
Beispiel #4
0
 /// <summary>
 /// Constructor.  Used for platform symbol files.
 /// </summary>
 /// <param name="loadOrdinal">Indicates the order in which the defining platform
 ///   symbol file was loaded.  Higher numbers indicate later loading, which translates
 ///   to higher priority.</param>
 /// <param name="fileIdent">Platform symbol file identifier, for the Info panel.</param>
 public DefSymbol(string label, int value, Source source, Type type,
                  FormatDescriptor.SubType formatSubType, int width, bool widthSpecified,
                  string comment, DirectionFlags direction, MultiAddressMask multiMask, string tag,
                  int loadOrdinal, string fileIdent)
     : this(label, value, source, type, formatSubType, width, widthSpecified,
            comment, direction, multiMask, tag)
 {
     LoadOrdinal    = loadOrdinal;
     FileIdentifier = fileIdent;
 }
Beispiel #5
0
        private static uint IOCreate(DirectionFlags dir, int number, int length)
        {
            long v =
                ((byte)dir << 30) |
                ((byte)'E' << 8) |
                (number << 0) |
                (length << 16);

            return((uint)v);
        }
Beispiel #6
0
        /// <summary>
        /// Create a DefSymbol given a Symbol, FormatDescriptor, and a few other things.  Used
        /// for deserialization.
        /// </summary>
        /// <param name="sym">Base symbol.</param>
        /// <param name="dfd">Format descriptor.</param>
        /// <param name="widthSpecified">Set if a width was explicitly specified.</param>
        /// <param name="comment">End-of-line comment.</param>
        /// <param name="direction">I/O direction.</param>
        /// <param name="multiMask">Bit mask to apply before comparisons.</param>
        public static DefSymbol Create(Symbol sym, FormatDescriptor dfd, bool widthSpecified,
                                       string comment, DirectionFlags direction, MultiAddressMask multiMask)
        {
            int width = dfd.Length;

            if (widthSpecified && sym.SymbolType == Type.Constant &&
                sym.SymbolSource != Source.Variable)
            {
                // non-variable constants don't have a width; override arg
                Debug.WriteLine("Overriding constant DefSymbol width");
                widthSpecified = false;
            }
            Debug.Assert(dfd.FormatType == FormatDescriptor.Type.NumericLE);
            return(new DefSymbol(sym.Label, sym.Value, sym.SymbolSource, sym.SymbolType,
                                 dfd.FormatSubType, width, widthSpecified, comment, direction, multiMask, string.Empty));
        }
Beispiel #7
0
        public static DirectionFlags GetFlagsTowardsRegion(int x, int z, int regionStartX, int regionEndX, int regionStartZ, int regionEndZ)
        {
            DirectionFlags directionX;
            DirectionFlags directionZ;

            if (x < regionStartX)
            {
                directionX = DirectionFlags.East | DirectionFlags.NorthEast | DirectionFlags.SouthEast;
            }
            else if (x >= regionEndX)
            {
                directionX = DirectionFlags.West | DirectionFlags.NorthWest | DirectionFlags.SouthWest;
            }
            else
            {
                directionX = DirectionFlags.All; // don't really care
            }
            DirectionFlags directionXMask = directionX | (DirectionFlags.North | DirectionFlags.South);

            if (z < regionStartZ)
            {
                directionZ = DirectionFlags.North | DirectionFlags.NorthEast | DirectionFlags.NorthWest;
            }
            else if (z >= regionEndZ)
            {
                directionZ = DirectionFlags.South | DirectionFlags.SouthEast | DirectionFlags.SouthWest;
            }
            else
            {
                directionZ = DirectionFlags.All; // don't really care
            }
            DirectionFlags directionZMask = directionZ | (DirectionFlags.East | DirectionFlags.West);


            var result = (directionX & directionZMask) | (directionZ & directionXMask);

            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// Constructor.  General form.
        /// </summary>
        /// <param name="label">Symbol's label.</param>
        /// <param name="value">Symbol's value.</param>
        /// <param name="source">Symbol source (general point of origin).</param>
        /// <param name="type">Symbol type.</param>
        /// <param name="formatSubType">Format descriptor sub-type, so we know how the
        ///   user wants the value to be displayed.</param>
        /// <param name="width">Variable width.</param>
        /// <param name="widthSpecified">True if width was explicitly specified.  If this is
        /// <param name="comment">End-of-line comment.</param>
        /// <param name="direction">I/O direction.</param>
        /// <param name="multiMask">Bit mask to apply before comparisons.</param>
        /// <param name="tag">Symbol tag, used for grouping platform symbols.</param>
        ///   false, the value of the "width" argument is ignored.</param>
        public DefSymbol(string label, int value, Source source, Type type,
                         LabelAnnotation labelAnno, FormatDescriptor.SubType formatSubType,
                         int width, bool widthSpecified, string comment,
                         DirectionFlags direction, MultiAddressMask multiMask, string tag)
            : this(label, value, source, type, labelAnno)
        {
            Debug.Assert(comment != null);
            Debug.Assert(tag != null);

            if (widthSpecified && type == Type.Constant && source != Source.Variable)
            {
                // non-variable constants don't have a width; override arg
                Debug.WriteLine("Overriding constant DefSymbol width");
                widthSpecified = false;
            }
            HasWidth = widthSpecified;
            if (!widthSpecified)
            {
                width = DEFAULT_WIDTH;
            }
            Debug.Assert(width >= MIN_WIDTH && width <= MAX_WIDTH);

            DataDescriptor = FormatDescriptor.Create(width,
                                                     FormatDescriptor.Type.NumericLE, formatSubType);
            Comment = comment;

            Debug.Assert(((int)direction & ~(int)DirectionFlags.ReadWrite) == 0);
            Direction = direction;

            // constants don't have masks
            if (type != Type.Constant)
            {
                MultiMask = multiMask;
            }

            Tag = tag;
        }
Beispiel #9
0
        public override DirectionFlags dir_triggered()
        {
            DirectionFlags dir = DirectionFlags.None;

            if (repeated(Inputs.Down))
            {
                dir |= DirectionFlags.Down;
            }
            else if (repeated(Inputs.Up))
            {
                dir |= DirectionFlags.Up;
            }

            if (repeated(Inputs.Left))
            {
                dir |= DirectionFlags.Left;
            }
            else if (repeated(Inputs.Right))
            {
                dir |= DirectionFlags.Right;
            }

            return(dir);
        }
Beispiel #10
0
 static uint IOCreate(DirectionFlags dir, int number, int length)
 {
     long v =
         ((byte)dir << 30) |
         ((byte)'E' << 8) |
         (number << 0) |
         (length << 16);
     return (uint)v;
 }
 public static int UnsetDirectionFlag(int startValue, DirectionFlags directionFlag)
 {
     return(startValue ^ ~((int)directionFlag));
 }
 public static int SetDirectionFlag(int startValue, DirectionFlags directionFlag)
 {
     return(startValue | (int)directionFlag);
 }
 public static bool HasDirectionFlag(int testValue, DirectionFlags directionFlag)
 {
     return((testValue & (int)directionFlag) > 0);
 }
    public Stack <Vector2Int> FindPath()
    {
        NodeInfo curNode = new NodeInfo();

        NodeInfo[] nextNodes = new NodeInfo[(int)DirectionFlags.COUNT];
        List <NodeInfo> .Enumerator enumerator;

        curNode.NodeId = m_startPoint;

        m_closeNodeList.Add(curNode);

        while (curNode.NodeId != m_endPoint && !(curNode.NodeId != m_startPoint && m_openNodeList.Count == 0))
        {
            for (DirectionFlags e = DirectionFlags.RIGHT; e < DirectionFlags.COUNT; e++)
            {
                nextNodes[(int)e]          = new NodeInfo();
                nextNodes[(int)e].ParentId = curNode.NodeId;
                switch (e)
                {
                case DirectionFlags.RIGHT:
                    nextNodes[(int)DirectionFlags.RIGHT].NodeId = new Vector2Int(curNode.NodeId.x + 1, curNode.NodeId.y);
                    break;

                case DirectionFlags.LEFT:
                    nextNodes[(int)DirectionFlags.LEFT].NodeId = new Vector2Int(curNode.NodeId.x - 1, curNode.NodeId.y);
                    break;

                case DirectionFlags.DOWN:
                    nextNodes[(int)DirectionFlags.DOWN].NodeId = new Vector2Int(curNode.NodeId.x, curNode.NodeId.y - 1);
                    break;

                case DirectionFlags.UP:
                    nextNodes[(int)DirectionFlags.UP].NodeId = new Vector2Int(curNode.NodeId.x, curNode.NodeId.y + 1);
                    break;
                }

                enumerator = m_closeNodeList.GetEnumerator();
                bool isDuplicated = false;
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.NodeId == nextNodes[(int)e].NodeId)
                    {
                        isDuplicated = true;
                        break;
                    }
                }

                if (isDuplicated)
                {
                    continue;
                }

                if (m_wayPointManager.GetWayPoint(nextNodes[(int)e].NodeId) != null)
                {
                    nextNodes[(int)e].ScoreG += curNode.ScoreG + 1;
                    nextNodes[(int)e].ScoreH  = Vector2.Distance(curNode.NodeId, m_endPoint);

                    enumerator = m_openNodeList.GetEnumerator();
                    bool isExist = false;

                    while (enumerator.MoveNext())
                    {
                        NodeInfo openNode = enumerator.Current;
                        if (openNode.NodeId == nextNodes[(int)e].NodeId &&
                            openNode.ScoreF > nextNodes[(int)e].ScoreF)
                        {
                            openNode.ScoreG   = nextNodes[(int)e].ScoreG;
                            openNode.ScoreH   = nextNodes[(int)e].ScoreH;
                            openNode.ParentId = nextNodes[(int)e].ParentId;
                            isExist           = true;
                            break;
                        }
                    }
                    if (!isExist)
                    {
                        m_openNodeList.Add(nextNodes[(int)e]);
                    }
                }
                else
                {
                    continue;
                }
            }//for


            enumerator = m_openNodeList.GetEnumerator();
            enumerator.MoveNext();
            curNode = enumerator.Current;

            while (enumerator.MoveNext())
            {
                NodeInfo nextNode = enumerator.Current;
                if (curNode.ScoreF > nextNode.ScoreF)
                {
                    curNode = nextNode;
                }
            }
            m_openNodeList.Remove(curNode);
            m_closeNodeList.Add(curNode);
        }

        NodeInfo[]         closeNodes = m_closeNodeList.ToArray();
        Stack <Vector2Int> pathStack  = new Stack <Vector2Int>();

        pathStack.Push(closeNodes[closeNodes.Length - 1].NodeId);
        pathStack.Push(closeNodes[closeNodes.Length - 1].ParentId);

        for (int i = closeNodes.Length - 2; i > 0; i--)
        {
            if (closeNodes[i].NodeId == pathStack.Peek())
            {
                pathStack.Push(closeNodes[i].ParentId);
            }
        }

        return(pathStack);
    }
Beispiel #15
0
 public static bool AnySouth(this DirectionFlags f)
 {
     return((f & (DirectionFlags.South | DirectionFlags.SouthEast | DirectionFlags.SouthWest)) != 0);
 }
Beispiel #16
0
        protected void update_input()
        {
            bool not_minimap_centered = false;

            // Mouse controls
            if (Input.IsControllingOnscreenMouse &&
                (Global.game_map.scrolling || Global.Input.mouseMoved))
            {
                Vector2 target_loc = mouse_loc;
                if (should_move_to_direct_input_loc(ref target_loc))
                {
                    //Global.game_system.play_se(System_Sounds.Cursor_Move); //Debug

                    if (Global.game_temp.minimap_call)
                    {
                        if (Loc != center_cursor_loc(false))
                        {
                            not_minimap_centered = true;
                        }
                    }

                    Instant_Movement = true;
                    Loc = target_loc; //new Vector2((int)target_loc.X, (int)target_loc.Y); //already made made int values //Debug
                    ((Scene_Map)Global.scene).update_info_image(true);

                    if (not_minimap_centered)
                    {
                        center_cursor();
                    }
                }
                return;
            }
            // Touch controls
            else if (Input.ControlScheme == ControlSchemes.Touch)
            {
                bool not_manual_target_window = Global.game_state.is_menuing &&
                                                ((Scene_Map)Global.scene).target_window_up &&
                                                !((Scene_Map)Global.scene).manual_targeting;

                if (!not_manual_target_window &&
                    Global.Input.touch_triggered() &&
                    Global.game_map.screen_loc_in_view(
                        Global.Input.touchPressPosition))
                {
                    Vector2 target_loc = touch_loc;
                    if (should_move_to_direct_input_loc(ref target_loc))
                    {
                        Instant_Movement = true;
                        Loc = target_loc; //new Vector2((int)target_loc.X, (int)target_loc.Y); //already made made int values //Debug
                        ((Scene_Map)Global.scene).update_info_image(true);
                    }
                }

                if (Global.Input.gesture_triggered(TouchGestures.FreeDrag))
                {
                    Global.game_map.scroll_vel(
                        -Global.Input.freeDragVector / TILE_SIZE);
                }
                return;
            }

            // Button controls
            if (ScrollingMovementBlocked && !Global.game_map.scrolling)
            {
                ScrollingMovementBlocked = false;
            }

            DirectionFlags dir8 = Input.direction_to_flag(Global.Input.dir8());

            if (dir8 == DirectionFlags.None)
            {
                LockedInputs = DirectionFlags.None;
            }

            // If moving normally
            if (!Global.game_temp.minimap_call && !speed_up_input())
            {
                dir8 = Global.Input.dir_triggered();
            }

            if (LockedInputs != DirectionFlags.None)
            {
                if (dir8 == LockedInputs)
                {
                    dir8 = DirectionFlags.None;
                }
            }
            if ((dir8 != DirectionFlags.None || !is_on_square) && Global.game_temp.minimap_call)
            {
                if (Loc != center_cursor_loc(false))
                {
                    not_minimap_centered = true;
                }
            }
            bool moved = false;

            switch (dir8)
            {
            case DirectionFlags.DownLeft:
                moved = move_down_left();
                break;

            case DirectionFlags.Down:
                moved = move_down();
                break;

            case DirectionFlags.DownRight:
                moved = move_down_right();
                break;

            case DirectionFlags.Left:
                moved = move_left();
                break;

            case DirectionFlags.Right:
                moved = move_right();
                break;

            case DirectionFlags.UpLeft:
                moved = move_up_left();
                break;

            case DirectionFlags.Up:
                moved = move_up();
                break;

            case DirectionFlags.UpRight:
                moved = move_up_right();
                break;
            }
            if (moved)
            {
                start_movement();
            }

            if (Global.game_temp.minimap_call && (dir8 != 0 || !is_on_square))
            {
                if (not_minimap_centered)
                {
                    center_cursor();
                }
            }
        }
Beispiel #17
0
        protected void range_edge_check()
        {
            if (Global.game_temp.menuing)
            {
                return;
            }
            int selected_unit_id = Global.game_system.Selected_Unit_Id;

            if (selected_unit_id == -1)
            {
                return;
            }
            //@Debug
            //if (!Global.game_map.active_team.Contains(selected_unit_id))
            //    return; //Multi
            Vector2    test_vector = Vector2.Zero;
            Directions dir         = Global.Input.dir8();

            switch (dir)
            {
            // Down left
            case Directions.DownLeft:
                test_vector = new Vector2(is_left_edge() ? 0 : -1, is_bottom_edge() ? 0 : 1);
                break;

            // Down
            case Directions.Down:
                test_vector = new Vector2(0, 1);
                break;

            // Down right
            case Directions.DownRight:
                test_vector = new Vector2(is_right_edge() ? 0 : 1, is_bottom_edge() ? 0 : 1);
                break;

            // Left
            case Directions.Left:
                test_vector = new Vector2(-1, 0);
                break;

            // Right
            case Directions.Right:
                test_vector = new Vector2(1, 0);
                break;

            // Up left
            case Directions.UpLeft:
                test_vector = new Vector2(is_left_edge() ? 0 : -1, is_on_top() ? 0 : -1);
                break;

            // Up
            case Directions.Up:
                test_vector = new Vector2(0, -1);
                break;

            // Up right
            case Directions.UpRight:
                test_vector = new Vector2(is_right_edge() ? 0 : 1, is_top_edge() ? 0 : -1);
                break;
            }
            if (!Global.game_map.move_range.Contains(Loc + test_vector) &&
                Global.game_map.move_range.Contains(Loc))
            {
                LockedInputs = Input.direction_to_flag(dir);
            }
        }
Beispiel #18
0
        protected override void UpdateMenu(bool active)
        {
            update_map_sprite();
            update_direction();
            // Black Screen
            update_black_screen();
            // Inputs
            bool input = active && Delay == 0 && !Closing && Black_Screen_Timer <= 0;

#if DEBUG
            if (Help_Window != null && input && Global.Input.pressed(Inputs.X))
            {
                DirectionFlags dir = Global.Input.dir_triggered();
                if (dir != DirectionFlags.None)
                {
                    StatusNodes[page].ActiveNode.cheat(this.unit, dir);
                    move_to(Help_Index);
                    Help_Window.add_remaining_text();

                    foreach (var status_page in Pages)
                    {
                        status_page.refresh(this.unit);
                    }
                    foreach (StatusUINode node in TopPanelNodes)
                    {
                        node.refresh(unit);
                    }
                }
                input = false;
            }
#endif

            // Cancel button
            CancelButton.Update(input);

            StatusNodes[page].Update(!input ? ControlSet.None :
                                     (Help_Window != null ?
                                      ControlSet.Movement : (ControlSet.Mouse | ControlSet.Touch)));

            if (input)
            {
                if (Help_Window == null)
                {
                    update_input();

                    var help_index = StatusNodes[page].consume_triggered(
                        MouseButtons.Left, TouchGestures.Tap);
                    if (help_index.IsNothing)
                    {
                        help_index = StatusNodes[page].consume_triggered(
                            TouchGestures.LongPress);
                    }

                    if (help_index.IsSomething)
                    {
                        Help_Index = StatusNodes[page][help_index].HelpLabel;
                        open_help();
                    }
                }
                else
                {
                    if (StatusNodes[page].ActiveNode.HelpLabel != Help_Index)
                    {
                        move_to(StatusNodes[page].ActiveNode.HelpLabel);
                    }

                    var help_index = StatusNodes[page].consume_triggered(
                        MouseButtons.Left, TouchGestures.Tap);
                    var help_cancel_index = StatusNodes[page].consume_triggered(
                        TouchGestures.LongPress);

                    if (Global.Input.triggered(Inputs.B) ||
                        Global.Input.triggered(Inputs.R) ||
                        Global.Input.mouse_click(MouseButtons.Right) ||
                        help_cancel_index.IsSomething ||
                        CancelButton.consume_trigger(MouseButtons.Left) ||
                        CancelButton.consume_trigger(TouchGestures.Tap))
                    {
                        close_help();
                    }

                    /* //Debug
                     * if (Global.Input.repeated(Inputs.Down))
                     * {
                     *  if (move(2))
                     *  {
                     *
                     *  }
                     * }
                     * if (Global.Input.repeated(Inputs.Up))
                     * {
                     *  if (move(8))
                     *  {
                     *
                     *  }
                     * }
                     * if (Global.Input.repeated(Inputs.Right))
                     * {
                     *  if (move(6))
                     *  {
                     *
                     *  }
                     * }
                     * if (Global.Input.repeated(Inputs.Left))
                     * {
                     *  if (move(4))
                     *  {
                     *
                     *  }
                     * }
                     * else if (Global.Input.triggered(Inputs.R) || Global.Input.triggered(Inputs.B))
                     * {
                     *  close_help();
                     * }*/
                }
                StatusCursors[page].update();
            }

            if (Help_Window != null)
            {
                Help_Window.update();
            }
            Background.update();
            // Top Panel
            Top_Panel.update();
            foreach (TextSprite label in Battle_Stat_Labels)
            {
                label.update();
            }
            // Pages
            foreach (Status_Page status_page in Pages)
            {
                status_page.update();
            }
            Left_Page_Arrow.update();
            Right_Page_Arrow.update();
        }
Beispiel #19
0
        // Granulometry on binary images
        public static Numa pixRunHistogramMorph(this Pix pixs, RunlengthFlagsForGranulometry runtype, DirectionFlags direction, int maxsize)
        {
            if (null == pixs)
            {
                throw new ArgumentNullException("pixs cannot be null.");
            }

            var pointer = Native.DllImports.pixRunHistogramMorph((HandleRef)pixs, (int)runtype, (int)direction, maxsize);

            if (IntPtr.Zero == pointer)
            {
                return(null);
            }
            else
            {
                return(new Numa(pointer));
            }
        }
Beispiel #20
0
 public DirectionFlags AllToOne(DirectionFlags mask)
 {
     return(dirs & mask);
 }
Beispiel #21
0
 public static bool AnyWest(this DirectionFlags f)
 {
     return((f & (DirectionFlags.West | DirectionFlags.NorthWest | DirectionFlags.SouthWest)) != 0);
 }