Beispiel #1
0
        /*
         * Request a game command from the uI and carry out whatever actions
         * go along with it.
         */
        public static void process_command(cmd_context ctx, bool no_request)
        {
            Game_Command cmd = new Game_Command();

            /* Reset so that when selecting items, we look in the default location */
            Misc.p_ptr.command_wrk = 0;

            /* If we've got a command to process, do it. */
            if (get(ctx, ref cmd, !no_request) != null)             //Was ==null...
            {
                int oldrepeats = cmd.nrepeats;
                int idx        = cmd_idx(cmd.command);
                int i;

                if (idx == -1)
                {
                    return;
                }

                for (i = 0; i < item_selector.Length; i++)
                {
                    item_selector_type itms = item_selector[i];

                    if (itms.command != cmd.command)
                    {
                        continue;
                    }

                    if (!cmd.arg_present[0])
                    {
                        int item = 0;

                        Misc.item_tester_hook = itms.filter;
                        if (!Object.Object.get_item(ref item, itms.prompt, itms.noop, cmd.command, itms.mode))
                        {
                            return;
                        }

                        cmd.set_arg_item(0, item);
                    }
                }

                /* XXX avoid dead objects from being re-used on repeat.
                 * this needs to be expanded into a general safety-check
                 * on args */
                if ((game_cmds[idx].arg_type[0] == cmd_arg_type.arg_ITEM) && cmd.arg_present[0])
                {
                    Object.Object o_ptr = Object.Object.object_from_item_idx(cmd.arg[0].value);
                    if (o_ptr.kind == null)
                    {
                        return;
                    }
                }

                /* Do some sanity checking on those arguments that might have
                 * been declared as "unknown", such as directions and targets. */
                switch (cmd.command)
                {
                case Command_Code.INSCRIBE:
                {
                    throw new NotImplementedException();
                    //char o_name[80];
                    //char tmp[80] = "";

                    //object_type *o_ptr = object_from_item_idx(cmd.arg[0].item);

                    //object_desc(o_name, sizeof(o_name), o_ptr, ODESC_PREFIX | ODESC_FULL);
                    //msg("Inscribing %s.", o_name);
                    //message_flush();

                    ///* Use old inscription */
                    //if (o_ptr.note)
                    //    strnfmt(tmp, sizeof(tmp), "%s", quark_str(o_ptr.note));

                    ///* Get a new inscription (possibly empty) */
                    //if (!get_string("Inscription: ", tmp, sizeof(tmp)))
                    //    return;

                    //cmd_set_arg_string(cmd, 1, tmp);
                    //break;
                }

                case Command_Code.OPEN:
                {
                    throw new NotImplementedException();
                    //if (Option.easy_open.value && (!cmd.arg_present[0] ||
                    //        cmd.arg[0].value == (int)Direction.UNKNOWN))
                    //{
                    //    int y, x;
                    //    int n_closed_doors, n_locked_chests;

                    //    throw new NotImplementedException();
                    //    n_closed_doors = count_feats(&y, &x, cave_iscloseddoor, false);
                    //    n_locked_chests = count_chests(&y, &x, false);

                    //    if (n_closed_doors + n_locked_chests == 1)
                    //        cmd_set_arg_direction(cmd, 0, coords_to_dir(y, x));
                    //}

                    //goto get_dir;
                }

                case Command_Code.CLOSE:
                {
                    throw new NotImplementedException();
                    //if (OPT(easy_open) && (!cmd.arg_present[0] ||
                    //        cmd.arg[0].direction == DIR_UNKNOWN))
                    //{
                    //    int y, x;

                    //    /* Count open doors */
                    //    if (count_feats(&y, &x, cave_isopendoor, false) == 1)
                    //        cmd_set_arg_direction(cmd, 0, coords_to_dir(y, x));
                    //}

                    //goto get_dir;
                }

                case Command_Code.DISARM:
                {
                    throw new NotImplementedException();
                    //if (OPT(easy_open) && (!cmd.arg_present[0] ||
                    //        cmd.arg[0].direction == DIR_UNKNOWN))
                    //{
                    //    int y, x;
                    //    int n_visible_traps, n_trapped_chests;

                    //    n_visible_traps = count_feats(&y, &x, cave_isknowntrap, true);
                    //    n_trapped_chests = count_chests(&y, &x, true);

                    //    if (n_visible_traps + n_trapped_chests == 1)
                    //        cmd_set_arg_direction(cmd, 0, coords_to_dir(y, x));
                    //}

                    //goto get_dir;
                }

                case Command_Code.TUNNEL:
                case Command_Code.WALK:
                case Command_Code.RUN:
                case Command_Code.JUMP:
                case Command_Code.BASH:
                case Command_Code.ALTER:
                case Command_Code.JAM:
                {
get_dir:
                    /* Direction hasn't been specified, so we ask for one. */
                    if (!cmd.arg_present[0] || cmd.arg[0].value == (int)Direction.UNKNOWN)
                    {
                        int dir;
                        if (!Xtra2.get_rep_dir(out dir))
                        {
                            return;
                        }


                        cmd.set_arg_direction(0, dir);
                    }

                    break;
                }

                case Command_Code.DROP:
                {
                    throw new NotImplementedException();
                    //if (!cmd.arg_present[1])
                    //{
                    //    object_type *o_ptr = object_from_item_idx(cmd.arg[0].item);
                    //    int amt = get_quantity(null, o_ptr.number);
                    //    if (amt <= 0)
                    //        return;

                    //    cmd_set_arg_number(cmd, 1, amt);
                    //}

                    //break;
                }

                /*
                 * These take an item number and a  "target" as arguments,
                 * though a target isn't always actually needed, so we'll
                 * only prompt for it via callback if the item being used needs it.
                 */
                case Command_Code.USE_WAND:
                case Command_Code.USE_ROD:
                case Command_Code.QUAFF:
                case Command_Code.ACTIVATE:
                case Command_Code.READ_SCROLL:
                case Command_Code.FIRE:
                case Command_Code.THROW:
                {
                    bool          get_target = false;
                    Object.Object o_ptr      = Object.Object.object_from_item_idx(cmd.arg[0].value);

                    /* If we couldn't resolve the item, then abort this */
                    if (o_ptr.kind == null)
                    {
                        break;
                    }

                    /* Thrown objects always need an aim, others might, depending
                     * on the object */
                    if (o_ptr.needs_aim() || cmd.command == Command_Code.THROW)
                    {
                        if (!cmd.arg_present[1])
                        {
                            get_target = true;
                        }
                        else if (cmd.arg[1].value == (int)Direction.UNKNOWN)
                        {
                            get_target = true;
                        }
                        else if (cmd.arg[1].value == (int)Direction.TARGET && !Target.okay())
                        {
                            get_target = true;
                        }
                    }

                    cmd.arg[1]       = new cmd_arg();
                    cmd.arg[1].value = 0;

                    if (get_target && !Xtra2.get_aim_dir(ref cmd.arg[1].value))
                    {
                        return;
                    }

                    Misc.p_ptr.confuse_dir(ref cmd.arg[1].value, false);
                    cmd.arg_present[1] = true;

                    break;
                }

                /* This takes a choice and a direction. */
                case Command_Code.CAST:
                {
                    throw new NotImplementedException();
                    //bool get_target = false;

                    //if (spell_needs_aim(Misc.p_ptr.Class.spell_book, cmd.arg[0].choice))
                    //{
                    //    if (!cmd.arg_present[1])
                    //        get_target = true;

                    //    if (cmd.arg[1].direction == DIR_UNKNOWN)
                    //        get_target = true;

                    //    if (cmd.arg[1].direction == DIR_TARGET && !target_okay())
                    //        get_target = true;
                    //}

                    //if (get_target && !get_aim_dir(&cmd.arg[1].direction))
                    //        return;

                    //player_confuse_dir(p_ptr, &cmd.arg[1].direction, false);
                    //cmd.arg_present[1] = true;

                    //break;
                }

                case Command_Code.WIELD:
                {
                    Object.Object o_ptr = Object.Object.object_from_item_idx(cmd.arg[0].value);
                    int           slot  = o_ptr.wield_slot();

                    /* Usually if the slot is taken we'll just replace the item in the slot,
                     * but in some cases we need to ask the user which slot they actually
                     * want to replace */
                    if (Misc.p_ptr.inventory[slot].kind != null)
                    {
                        if (o_ptr.tval == Object.TVal.TV_RING)
                        {
                            string q = "Replace which ring? ";
                            string s = "Error in obj_wield, please report";
                            Misc.item_tester_hook = Object.Object.obj_is_ring;
                            if (!Object.Object.get_item(ref slot, q, s, Command_Code.WIELD, Misc.USE_EQUIP))
                            {
                                return;
                            }
                        }

                        if (o_ptr.is_ammo() &&
                            !Misc.p_ptr.inventory[slot].similar(o_ptr, Object.Object.object_stack_t.OSTACK_QUIVER))
                        {
                            string q = "Replace which ammunition? ";
                            string s = "Error in obj_wield, please report";
                            Misc.item_tester_hook = Object.Object.obj_is_ammo;
                            if (!Object.Object.get_item(ref slot, q, s, Command_Code.WIELD, Misc.USE_EQUIP))
                            {
                                return;
                            }
                        }
                    }

                    /* Set relevant slot */
                    cmd.set_arg_number(1, slot);

                    break;
                }

                default:
                {
                    /* I can see the point of the compiler warning, but still... */
                    break;
                }
                }

                /* Command repetition */
                if (game_cmds[idx].repeat_allowed)
                {
                    /* Auto-repeat only if there isn't already a repeat length. */
                    if (game_cmds[idx].nrepeats > 0 && cmd.nrepeats == 0)
                    {
                        Game_Command.set_repeat(game_cmds[idx].nrepeats);
                    }
                }
                else
                {
                    cmd.nrepeats = 0;
                    repeating    = false;
                }

                /*
                 * The command gets to unset this if it isn't appropriate for
                 * the user to repeat it.
                 */
                repeat_prev_allowed = true;

                if (game_cmds[idx].fn != null)
                {
                    game_cmds[idx].fn(cmd.command, cmd.arg);
                }

                /* If the command hasn't changed nrepeats, count this execution. */
                if (cmd.nrepeats > 0 && oldrepeats == Game_Command.get_nrepeats())
                {
                    Game_Command.set_repeat(oldrepeats - 1);
                }
            }
        }
Beispiel #2
0
 /* ------------------------------------------------------------------------
  * Temporary (hopefully) hackish solutions.
  * ------------------------------------------------------------------------ */
 public static void check_panel(Game_Event.Event_Type type, Game_Event data, object user)
 {
     Xtra2.verify_panel();
 }
Beispiel #3
0
        private const int INFO_SCREENS = 2;          /* Number of screens in character info mode */

        /*
         * Hack -- redraw the screen
         *
         * This command performs various low level updates, clears all the "extra"
         * windows, does a total redraw of the main window, and requests all of the
         * interesting updates and redraws that I can think of.
         *
         * This command is also used to "instantiate" the results of the user
         * selecting various things, such as graphics mode, so it must call
         * the "TERM_XTRA_REACT" hook before redrawing the windows.
         *
         */
        public static void redraw()
        {
            int j;

            Term old = Term.instance;


            /* Low level flush */
            Term.flush();

            /* Reset "inkey()" */
            Utilities.flush();

            if (Player.Player.character_dungeon)
            {
                Xtra2.verify_panel();
            }


            /* Hack -- React to changes */
            Term.xtra(TERM_XTRA.REACT, 0);


            /* Combine and Reorder the pack (later) */
            Misc.p_ptr.notice |= (Misc.PN_COMBINE | Misc.PN_REORDER);


            /* Update torch */
            Misc.p_ptr.update |= (Misc.PU_TORCH);

            /* Update stuff */
            Misc.p_ptr.update |= (Misc.PU_BONUS | Misc.PU_HP | Misc.PU_MANA | Misc.PU_SPELLS);

            /* Fully update the visuals */
            Misc.p_ptr.update |= (Misc.PU_FORGET_VIEW | Misc.PU_UPDATE_VIEW | Misc.PU_MONSTERS);

            /* Redraw everything */
            Misc.p_ptr.redraw |= (uint)(Misc.PR_BASIC | Misc.PR_EXTRA | Misc.PR_MAP | Misc.PR_INVEN | Misc.PR_EQUIP |
                                        Misc.PR_MESSAGE | Misc.PR_MONSTER | Misc.PR_OBJECT |
                                        Misc.PR_MONLIST | Misc.PR_ITEMLIST);

            /* Clear screen */
            Term.clear();

            /* Hack -- update */
            Misc.p_ptr.handle_stuff();

            /* Place the cursor on the player */
            if (Player.Player.character_dungeon)
            {
                Cave.move_cursor_relative(Misc.p_ptr.px, Misc.p_ptr.py);
            }


            /* Redraw every window */
            for (j = 0; j < Misc.ANGBAND_TERM_MAX; j++)
            {
                if (Misc.angband_term[j] == null)
                {
                    continue;
                }

                Misc.angband_term[j].activate();
                Term.redraw();
                Term.fresh();
                old.activate();
            }
        }