Example #1
0
        /** Returns the string named `name`. This symbol must exist. */
        public string getstr(string name)
        {
            Parser_Value v = getval(name);

            Misc.assert((v.spec.type & ~PARSE_T.OPT) == PARSE_T.STR);
            return((string)v.value);
        }
Example #2
0
        public char getchar(string name)
        {
            Parser_Value v = getval(name);

            Misc.assert((v.spec.type & ~PARSE_T.OPT) == PARSE_T.CHAR);
            return((char)v.value);
        }
Example #3
0
        public random_value getrand(string name)
        {
            Parser_Value v = getval(name);

            Misc.assert((v.spec.type & ~PARSE_T.OPT) == PARSE_T.RAND);
            return((random_value)v.value);
        }
Example #4
0
        //All below functions had flags and size. flags was a byte* and size was a size_t

        /**
         * Sets multiple bitflags in a bitfield.
         *
         * The flags specified in `...` are set in `flags`. The bitfield size is
         * supplied in `size`. true is returned when changes were made, false
         * otherwise.
         *
         * WARNING: FLAG_END must be the final argument in the `...` list. <- LIES
         */
        public bool set(params int[] values)
        {
            bool delta = false;

            /* Process each flag in the va-args */
            for (int i = 0; i < values.Length; i++)
            {
                int f = values[i];

                int  flag_offset = FLAG_OFFSET(f);
                byte flag_binary = FLAG_BINARY(f);

                Misc.assert(flag_offset < size);

                /* !flag_has() */
                if ((data[flag_offset] & flag_binary) == 0)
                {
                    delta = true;
                }

                /* flag_on() */
                data[flag_offset] |= flag_binary;
            }

            return(delta);
        }
Example #5
0
        static Parser.Error parse_prefs_e(Parser p)
        {
            int tvi, a;

            prefs_data d = p.priv as prefs_data;

            Misc.assert(d != null);
            if (d.bypass)
            {
                return(Parser.Error.NONE);
            }

            tvi = TVal.find_idx(p.getsym("tval"));
            if (tvi < 0 || tvi >= Misc.tval_to_attr.Length)
            {
                return(Parser.Error.UNRECOGNISED_TVAL);
            }

            a = p.getint("attr");
            if (a != 0)
            {
                Misc.tval_to_attr[tvi] = Utilities.num_to_attr(a);
            }

            return(Parser.Error.NONE);
        }
Example #6
0
        static Parser.Error parse_prefs_c(Parser p)
        {
            int mode;

            prefs_data d = p.priv as prefs_data;

            Misc.assert(d != null);
            if (d.bypass)
            {
                return(Parser.Error.NONE);
            }

            mode = p.getint("mode");
            if (mode < 0 || mode >= (int)Keymap.Mode.MAX)
            {
                return(Parser.Error.OUT_OF_BOUNDS);
            }

            ui_event[] temp = UIEvent.keypress_from_text(p.getstr("key"));

            if (temp[0].type != ui_event_type.EVT_KBRD || temp.Length > 1)
            {
                return(Parser.Error.FIELD_TOO_LONG);
            }

            Keymap.add(mode, temp[0].key, d.keymap_buffer, d.user);

            return(Parser.Error.NONE);
        }
Example #7
0
        static Parser.Error parse_prefs_m(Parser p)
        {
            Message_Type type;
            string       attr;

            prefs_data d = p.priv as prefs_data;

            Misc.assert(d != null);
            if (d.bypass)
            {
                return(Parser.Error.NONE);
            }

            type = (Message_Type)p.getint("type");
            attr = p.getsym("attr");

            ConsoleColor a = Utilities.color_text_to_attr(attr);

            if (a < 0)
            {
                return(Parser.Error.INVALID_COLOR);
            }

            Message.color_define(type, a);

            return(Parser.Error.NONE);
        }
Example #8
0
        public uint getuint(string name)
        {
            Parser_Value v = getval(name);

            Misc.assert((v.spec.type & ~PARSE_T.OPT) == PARSE_T.UINT);
            return((uint)v.value);
        }
Example #9
0
        /**
         * Remove a keymap.  Return true if one was removed.
         */
        public static bool remove(int keymap, keypress trigger)
        {
            Keymap k;
            Keymap prev = null;

            Misc.assert(keymap >= 0 && keymap < (int)Mode.MAX);

            for (k = keymaps[keymap]; k != null; k = k.next)
            {
                if (k.key.code == trigger.code && k.key.mods == trigger.mods)
                {
                    if (prev != null)
                    {
                        prev.next = k.next;
                    }
                    else
                    {
                        keymaps[keymap] = k.next;
                    }
                    return(true);
                }

                prev = k;
            }

            return(false);
        }
Example #10
0
        /* Places a trap. All traps are untyped until discovered. */
        public static void place_trap(Cave c, int y, int x)
        {
            Misc.assert(Cave.cave_in_bounds(c, y, x));
            Misc.assert(Cave.cave_isempty(c, y, x));

            /* Place an invisible trap */
            Cave.cave_set_feat(c, y, x, Cave.FEAT_INVIS);
        }
Example #11
0
        static Error parse_specs(Parser_Hook h, string fmt)
        {
            Misc.assert(h != null);
            Misc.assert(fmt != null);

            string[] split = fmt.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (split.Length == 0)
            {
                return(Error.GENERIC);
            }

            h.dir = split[0];

            int i = 1;

            while (i < split.Length)
            {
                /* Lack of a type is legal; that means we're at the end of the
                 * line. */
                string stype = split[i++];

                /* Lack of a name, on the other hand... */
                if (i >= split.Length)
                {
                    clean_specs(h);
                    return(Error.GENERIC);
                }
                string name = split[i++];

                /* Grab a type, check to see if we have a mandatory type
                 * following an optional type. */
                PARSE_T type = parse_type(stype);
                if (type == PARSE_T.NONE)
                {
                    clean_specs(h);
                    return(Error.GENERIC);
                }
                if ((type & PARSE_T.OPT) == 0 && h.specs.Count > 0 && (h.specs.Last().type & PARSE_T.OPT) != 0)
                {
                    clean_specs(h);
                    return(Error.GENERIC);
                }
                if (h.specs.Count > 0 && ((h.specs.Last().type & ~PARSE_T.OPT) == PARSE_T.STR))
                {
                    clean_specs(h);
                    return(Error.GENERIC);
                }

                /* Save this spec. */
                Hook_Spec hs = new Hook_Spec();
                hs.type = type;
                hs.name = name;
                h.specs.Add(hs);
            }

            return(Error.NONE);
        }
Example #12
0
        /**
         * Tests if all of the multiple bitflags are set in a bitfield.
         *
         * true is returned if all of the flags specified in `...` are set in `flags`,
         * false otherwise. The bitfield size is supplied in `size`.
         *
         * WARNING: FLAG_END must be the final argument in the `...` list.
         */
        public bool test_all(params int[] values)
        {
            int  flag_offset;
            int  flag_binary;
            bool delta = true;

            /* Process each flag in the va-args */
            for (int i = 0; i < values.Length; i++)
            {
                int f = values[i];
                flag_offset = FLAG_OFFSET(f);
                flag_binary = FLAG_BINARY(f);

                Misc.assert(flag_offset < size);

                /* !flag_has() */
                if ((data[flag_offset] & flag_binary) == 0)
                {
                    delta = false;
                    break;
                }
            }

            return(delta);



            //size_t flag_offset;
            //int flag_binary;
            //int f;
            //va_list args;
            //bool delta = true;

            //va_start(args, size);

            ///* Process each flag in the va-args */
            //for (f = va_arg(args, int); f != FLAG_END; f = va_arg(args, int))
            //{
            //    flag_offset = FLAG_OFFSET(f);
            //    flag_binary = FLAG_BINARY(f);

            //    assert(flag_offset < size);

            //    /* !flag_has() */
            //    if (!(flags[flag_offset] & flag_binary))
            //    {
            //        delta = false;
            //        break;
            //    }
            //}

            //va_end(args);

            //return delta;
        }
Example #13
0
        /**
         * Tests if a flag is "on" in a bitflag set.
         *
         * true is returned when `flag` is on in `flags`, and false otherwise.
         * The flagset size is supplied in `size`.
         */
        public bool has(int flag)
        {
            int  flag_offset = FLAG_OFFSET(flag);
            byte flag_binary = FLAG_BINARY(flag);

            //if (flag == FLAG_END) return false;

            Misc.assert(flag_offset < size);

            return((data[flag_offset] & flag_binary) != 0);
        }
Example #14
0
 private Parser_Value getval(string name)
 {
     foreach (Parser_Value v in values)
     {
         if (v.spec.name == name)
         {
             return(v);
         }
     }
     Misc.assert(false);
     return(null);
 }
Example #15
0
        public void set_arg_direction(int n, int dir)
        {
            int idx = cmd_idx(command);

            Misc.assert(n <= CMD_MAX_ARGS);
            Misc.assert((game_cmds[idx].arg_type[n] & cmd_arg_type.arg_DIRECTION) != 0);

            arg[n]         = new cmd_arg();
            arg[n].value   = dir;
            arg_type[n]    = cmd_arg_type.arg_DIRECTION;
            arg_present[n] = true;
        }
Example #16
0
        public void set_arg_choice(int n, string choice)
        {
            int idx = cmd_idx(command);

            Misc.assert(n <= CMD_MAX_ARGS);
            Misc.assert((game_cmds[idx].arg_type[n] & cmd_arg_type.arg_STRING) != 0);

            arg[n]         = new cmd_arg();
            arg[n].text    = choice;
            arg_type[n]    = cmd_arg_type.arg_STRING;
            arg_present[n] = true;
        }
Example #17
0
        public void set_arg_item(int n, int item)
        {
            int idx = cmd_idx(command);

            Misc.assert(n <= CMD_MAX_ARGS);
            Misc.assert((game_cmds[idx].arg_type[n] & cmd_arg_type.arg_ITEM) != 0);

            arg[n]         = new cmd_arg();
            arg[n].value   = item;
            arg_type[n]    = cmd_arg_type.arg_ITEM;
            arg_present[n] = true;
        }
Example #18
0
        public void set_arg_number(int n, int num)
        {
            int idx = cmd_idx(command);

            Misc.assert(n <= CMD_MAX_ARGS);
            Misc.assert((game_cmds[idx].arg_type[n] & cmd_arg_type.arg_NUMBER) != 0);

            arg[n]         = new cmd_arg();
            arg[n].value   = num;
            arg_type[n]    = cmd_arg_type.arg_NUMBER;
            arg_present[n] = true;
        }
Example #19
0
        public void set_arg_choice(int n, int choice)
        {
            int idx = cmd_idx(command);

            Misc.assert(n <= CMD_MAX_ARGS);
            Misc.assert((game_cmds[idx].arg_type[n] & cmd_arg_type.arg_CHOICE) != 0);

            arg[n]         = new cmd_arg();
            arg[n].value   = choice;
            arg_type[n]    = cmd_arg_type.arg_CHOICE;
            arg_present[n] = true;
        }
Example #20
0
        public void set_arg_point(int n, int x, int y)
        {
            int idx = cmd_idx(command);

            Misc.assert(n <= CMD_MAX_ARGS);
            Misc.assert((game_cmds[idx].arg_type[n] & cmd_arg_type.arg_POINT) != 0);

            arg[n]         = new cmd_arg();
            arg[n].point   = new Loc();
            arg[n].point.x = x;
            arg[n].point.y = y;
            arg_type[n]    = cmd_arg_type.arg_POINT;
            arg_present[n] = true;
        }
Example #21
0
        public static void add_handler(Event_Type type, Handler fn, object user)
        {
            event_handler_entry e;

            Misc.assert(fn != null);

            /* Make a new entry */
            e      = new event_handler_entry();
            e.fn   = fn;
            e.user = user;

            /* Add it to the head of the appropriate list */
            e.next = event_handlers[(int)type];
            event_handlers[(int)type] = e;
        }
Example #22
0
        /**
         * Find a keymap, given a keypress.
         */
        public static keypress[] find(int keymap, keypress kc)
        {
            Keymap k;

            Misc.assert(keymap >= 0 && keymap < (int)Keymap.Mode.MAX);
            for (k = keymaps[keymap]; k != null; k = k.next)
            {
                if (k.key.code == kc.code && k.key.mods == kc.mods)
                {
                    return(k.actions);
                }
            }

            return(null);
        }
Example #23
0
        Region active;                  /* Subregion actually active for selection */


        /**
         * Initialise a menu, using the skin and iter functions specified.
         */
        public void Init(skin_id skin_id, menu_iter iter)
        {
            menu_skin skin = menu_find_skin(skin_id);

            Misc.assert(skin != null, "menu skin not found!");
            Misc.assert(iter != null, "menu iter not found!");

            /* Wipe the struct */
            //memset(menu, 0, sizeof *menu); //meh

            /* Menu-specific initialisation */
            row_funcs = iter;
            this.skin = skin;
            cursor    = 0;
        }
Example #24
0
        /**
         * Load another file.
         */
        static Parser.Error parse_prefs_load(Parser p)
        {
            prefs_data d = p.priv as prefs_data;
            string     file;

            Misc.assert(d != null);
            if (d.bypass)
            {
                return(Parser.Error.NONE);
            }

            file = p.getstr("file");
            process_pref_file(file, true, d.user);

            return(Parser.Error.NONE);
        }
Example #25
0
        /**
         * Clears one flag in a bitfield.
         *
         * The bitflag identified by `flag` is cleared in `flags`. The bitfield size
         * is supplied in `size`.  true is returned when changes were made, false
         * otherwise.
         */
        public bool off(int flag)
        {
            int flag_offset = FLAG_OFFSET(flag);
            int flag_binary = FLAG_BINARY(flag);

            Misc.assert(flag_offset < size);

            if ((data[flag_offset] & flag_binary) == 0)
            {
                return(false);
            }

            data[flag_offset] &= (byte)~flag_binary;

            return(true);
        }
Example #26
0
        /**
         * Add a keymap to the mappings table.
         */
        public static void add(int keymap, keypress trigger, keypress[] actions, bool user)
        {
            Keymap k = new Keymap();

            Misc.assert(keymap >= 0 && keymap < (int)Mode.MAX);

            remove(keymap, trigger);

            k.key     = trigger;
            k.actions = make(actions);
            k.user    = user;

            k.next          = keymaps[keymap];
            keymaps[keymap] = k;

            return;
        }
Example #27
0
        static Parser.Error parse_prefs_expr(Parser p)
        {
            prefs_data d = p.priv as prefs_data;

            string v;
            string str;
            string expr;
            char   f = '\0';           //Nick: No default originally, I am just guessing here...

            Misc.assert(d != null);

            /* XXX this can be avoided with a rewrite of process_pref_file_expr */
            str = expr = p.getstr("expr");

            /* Parse the expr */
            v = process_pref_file_expr(ref expr, ref f);

            /* Set flag */
            d.bypass = (v == "0");

            return(Parser.Error.NONE);
        }
Example #28
0
        static Parser.Error parse_prefs_a(Parser p)
        {
            string act;

            prefs_data d = p.priv as prefs_data;

            Misc.assert(d != null);
            if (d.bypass)
            {
                return(Parser.Error.NONE);
            }

            act = p.getstr("act");
            ui_event[] evts = UIEvent.keypress_from_text(act);

            d.keymap_buffer = new keypress[evts.Count()];
            for (int i = 0; i < evts.Count(); i++)
            {
                d.keymap_buffer[i] = evts[i].key;
            }

            return(Parser.Error.NONE);
        }
Example #29
0
        /** Registers a parser hook.
         *
         * Hooks have the following format:
         *   <fmt>  ::= <name> [<type> <name>]* [?<type> <name>]*
         *   <type> ::= int | str | sym | rand | char
         * The first <name> is called the directive for this hook. Any other hooks with
         * the same directive are superseded by this hook. It is an error for a
         * mandatory field to follow an optional field. It is an error for any field to
         * follow a field of type `str`, since `str` fields are not delimited and will
         * consume the entire rest of the line.
         */
        public Error Register(string fmt, ParseFunc pf)
        {
            //Misc.assert(p); //if p (self) was null, we wouldn't be here
            Misc.assert(fmt != null);
            Misc.assert(pf != null);

            Parser_Hook h = new Parser_Hook();

            h.func = pf;

            /*h.next = p.hooks;
             * h.func = func;*/
            Error r = parse_specs(h, fmt);

            if (r != Error.NONE)
            {
                return(r);
            }

            hooks.Add(h);
            //p.hooks = h;
            //mem_free(cfmt);
            return(Error.NONE);
        }
Example #30
0
        /* Compute the direction (in the angband 123456789 sense) from a point to a
         * point. We decide to use diagonals if dx and dy are within a factor of two of
         * each other; otherwise we choose a cardinal direction. */
        public static Direction direction_to(Loc from, Loc to)
        {
            int adx = Math.Abs(to.x - from.x);
            int ady = Math.Abs(to.y - from.y);
            int dx  = to.x - from.x;
            int dy  = to.y - from.y;

            if (dx == 0 && dy == 0)
            {
                return(Direction.NONE);
            }

            if (dx >= 0 && dy >= 0)
            {
                if (adx < ady * 2 && ady < adx * 2)
                {
                    return(Direction.NE);
                }
                else if (adx > ady)
                {
                    return(Direction.E);
                }
                else
                {
                    return(Direction.N);
                }
            }
            else if (dx > 0 && dy < 0)
            {
                if (adx < ady * 2 && ady < adx * 2)
                {
                    return(Direction.SE);
                }
                else if (adx > ady)
                {
                    return(Direction.E);
                }
                else
                {
                    return(Direction.S);
                }
            }
            else if (dx < 0 && dy > 0)
            {
                if (adx < ady * 2 && ady < adx * 2)
                {
                    return(Direction.NW);
                }
                else if (adx > ady)
                {
                    return(Direction.W);
                }
                else
                {
                    return(Direction.N);
                }
            }
            else if (dx <= 0 && dy <= 0)
            {
                if (adx < ady * 2 && ady < adx * 2)
                {
                    return(Direction.SW);
                }
                else if (adx > ady)
                {
                    return(Direction.W);
                }
                else
                {
                    return(Direction.S);
                }
            }

            Misc.assert(false);
            return(Direction.UNKNOWN);
        }