コード例 #1
0
        /*
         * Let the user select an item, save its "index"
         *
         * Return true only if an acceptable item was chosen by the user.
         *
         * The selected item must satisfy the "item_tester_hook()" function,
         * if that hook is set, and the "item_tester_tval", if that value is set.
         *
         * All "item_tester" restrictions are cleared before this function returns.
         *
         * The user is allowed to choose acceptable items from the equipment,
         * inventory, or floor, respectively, if the proper flag was given,
         * and there are any acceptable items in that location.
         *
         * The equipment or inventory are displayed (even if no acceptable
         * items are in that location) if the proper flag was given.
         *
         * If there are no acceptable items available anywhere, and "str" is
         * not null, then it will be used as the text of a warning message
         * before the function returns.
         *
         * Note that the user must press "-" to specify the item on the floor,
         * and there is no way to "examine" the item on the floor, while the
         * use of "capital" letters will "examine" an inventory/equipment item,
         * and prompt for its use.
         *
         * If a legal item is selected from the inventory, we save it in "cp"
         * directly (0 to 35), and return true.
         *
         * If a legal item is selected from the floor, we save it in "cp" as
         * a negative (-1 to -511), and return true.
         *
         * If no item is available, we do nothing to "cp", and we display a
         * warning message, using "str" if available, and return false.
         *
         * If no item is selected, we do nothing to "cp", and return false.
         *
         * Global "p_ptr.command_wrk" is used to choose between equip/inven/floor
         * listings.  It is equal to USE_INVEN or USE_EQUIP or USE_FLOOR, except
         * when this function is first called, when it is equal to zero, which will
         * cause it to be set to USE_INVEN.
         *
         * We always erase the prompt when we are done, leaving a blank line,
         * or a warning message, if appropriate, if no items are available.
         *
         * Note that only "acceptable" floor objects get indexes, so between two
         * commands, the indexes of floor objects may change.  XXX XXX XXX
         */
        public static bool get_item(ref int cp, string pmt, string str, Command_Code cmd, int mode)
        {
            int  py     = Misc.p_ptr.py;
            int  px     = Misc.p_ptr.px;
            char cmdkey = Command.lookup_key(cmd);

            keypress which;

            int j, k = 0;

            int i1, i2;
            int e1, e2;
            int f1, f2;

            bool done, item;

            bool oops = false;

            bool use_inven   = ((mode & Misc.USE_INVEN) != 0 ? true : false);
            bool use_equip   = ((mode & Misc.USE_EQUIP) != 0 ? true : false);
            bool use_floor   = ((mode & Misc.USE_FLOOR) != 0 ? true : false);
            bool use_quiver  = ((mode & Misc.QUIVER_TAGS) != 0 ? true : false);
            bool is_harmless = ((mode & Misc.IS_HARMLESS) != 0 ? true : false);
            bool quiver_tags = ((mode & Misc.QUIVER_TAGS) != 0 ? true : false);

            olist_detail_t olist_mode = 0;

            bool allow_inven = false;
            bool allow_equip = false;
            bool allow_floor = false;

            bool toggle = false;

            string tmp_val;        //[160];
            string out_val;        //[160];

            int[] floor_list = new int[Misc.MAX_FLOOR_STACK];
            int   floor_num;

            bool show_list = true;


            /* Object list display modes */
            if ((mode & Misc.SHOW_FAIL) != 0)
            {
                olist_mode |= (olist_detail_t.OLIST_FAIL);
            }
            else
            {
                olist_mode |= (olist_detail_t.OLIST_WEIGHT);
            }
            if ((mode & Misc.SHOW_PRICES) != 0)
            {
                olist_mode |= (olist_detail_t.OLIST_PRICE);
            }

            /* Paranoia XXX XXX XXX */
            Utilities.message_flush();


            /* Not done */
            done = false;

            /* No item selected */
            item = false;


            /* Full inventory */
            i1 = 0;
            i2 = Misc.INVEN_PACK - 1;

            /* Forbid inventory */
            if (!use_inven)
            {
                i2 = -1;
            }

            /* Restrict inventory indexes */
            while ((i1 <= i2) && (!Object.get_item_okay(i1)))
            {
                i1++;
            }
            while ((i1 <= i2) && (!get_item_okay(i2)))
            {
                i2--;
            }

            /* Accept inventory */
            if (i1 <= i2)
            {
                allow_inven = true;
            }


            /* Full equipment */
            e1 = Misc.INVEN_WIELD;
            e2 = Misc.ALL_INVEN_TOTAL - 1;

            /* Forbid equipment */
            if (!use_equip)
            {
                e2 = -1;
            }

            /* Restrict equipment indexes */
            while ((e1 <= e2) && (!get_item_okay(e1)))
            {
                e1++;
            }
            while ((e1 <= e2) && (!get_item_okay(e2)))
            {
                e2--;
            }

            /* Accept equipment */
            if (e1 <= e2)
            {
                allow_equip = true;
            }


            /* Scan all non-gold objects in the grid */
            floor_num = scan_floor(floor_list, floor_list.Length, py, px, 0x03);

            /* Full floor */
            f1 = 0;
            f2 = floor_num - 1;

            /* Forbid floor */
            if (!use_floor)
            {
                f2 = -1;
            }

            /* Restrict floor indexes */
            while ((f1 <= f2) && (!get_item_okay(0 - floor_list[f1])))
            {
                f1++;
            }
            while ((f1 <= f2) && (!get_item_okay(0 - floor_list[f2])))
            {
                f2--;
            }

            /* Accept floor */
            if (f1 <= f2)
            {
                allow_floor = true;
            }


            /* Require at least one legal choice */
            if (!allow_inven && !allow_equip && !allow_floor)
            {
                /* Oops */
                oops = true;
                done = true;
            }

            /* Analyze choices */
            else
            {
                /* Hack -- Start on equipment if requested */
                if ((Misc.p_ptr.command_wrk == Misc.USE_EQUIP) && use_equip)
                {
                    Misc.p_ptr.command_wrk = Misc.USE_EQUIP;
                }

                /* If we are using the quiver then start on equipment */
                else if (use_quiver)
                {
                    Misc.p_ptr.command_wrk = Misc.USE_EQUIP;
                }

                /* Use inventory if allowed */
                else if (use_inven)
                {
                    Misc.p_ptr.command_wrk = Misc.USE_INVEN;
                }

                /* Use equipment if allowed */
                else if (use_equip)
                {
                    Misc.p_ptr.command_wrk = Misc.USE_EQUIP;
                }

                /* Use floor if allowed */
                else if (use_floor)
                {
                    Misc.p_ptr.command_wrk = Misc.USE_FLOOR;
                }

                /* Hack -- Use (empty) inventory */
                else
                {
                    Misc.p_ptr.command_wrk = Misc.USE_INVEN;
                }
            }


            /* Start out in "display" mode */
            if (show_list)
            {
                /* Save screen */
                Utilities.screen_save();
            }


            /* Repeat until done */
            while (!done)
            {
                int ni = 0;
                int ne = 0;

                /* Scan windows */
                for (j = 0; j < Misc.ANGBAND_TERM_MAX; j++)
                {
                    /* Unused */
                    if (Misc.angband_term[j] == null)
                    {
                        continue;
                    }

                    /* Count windows displaying inven */
                    if ((Player.Player_Other.instance.window_flag[j] & (Misc.PW_INVEN)) != 0)
                    {
                        ni++;
                    }

                    /* Count windows displaying equip */
                    if ((Player.Player_Other.instance.window_flag[j] & (Misc.PW_EQUIP)) != 0)
                    {
                        ne++;
                    }
                }

                /* Toggle if needed */
                if (((Misc.p_ptr.command_wrk == Misc.USE_EQUIP) && ni != 0 && ne == 0) ||
                    ((Misc.p_ptr.command_wrk == Misc.USE_INVEN) && ni == 0 && ne != 0))
                {
                    /* Toggle */
                    Command_Info.toggle_inven_equip();

                    /* Track toggles */
                    toggle = !toggle;
                }

                /* Redraw */
                Misc.p_ptr.redraw |= (Misc.PR_INVEN | Misc.PR_EQUIP);

                /* Redraw windows */
                Misc.p_ptr.redraw_stuff();

                /* Viewing inventory */
                if (Misc.p_ptr.command_wrk == Misc.USE_INVEN)
                {
                    /* Redraw if needed */
                    if (show_list)
                    {
                        show_inven(olist_mode);
                    }

                    /* Begin the prompt */
                    out_val = "Inven:";

                    /* List choices */
                    if (i1 <= i2)
                    {
                        /* Build the prompt */
                        tmp_val = String.Format(" {0}-{1},", index_to_label(i1), index_to_label(i2));

                        /* Append */
                        out_val += tmp_val;
                    }

                    /* Indicate ability to "view" */
                    if (!show_list)
                    {
                        out_val += " * to see,";
                        Button.button_add("[*]", '*');
                    }

                    /* Indicate legality of "toggle" */
                    if (use_equip)
                    {
                        out_val += " / for Equip,";
                        Button.button_add("[/]", '/');
                    }

                    /* Indicate legality of the "floor" */
                    if (allow_floor)
                    {
                        out_val += " - for floor,";
                        Button.button_add("[-]", '-');
                    }
                }

                /* Viewing equipment */
                else if (Misc.p_ptr.command_wrk == Misc.USE_EQUIP)
                {
                    /* Redraw if needed */
                    if (show_list)
                    {
                        show_equip(olist_mode);
                    }

                    /* Begin the prompt */
                    out_val = "Equip:";

                    /* List choices */
                    if (e1 <= e2)
                    {
                        /* Build the prompt */
                        tmp_val = String.Format(" {0}-{1},", index_to_label(e1), index_to_label(e2));

                        /* Append */
                        out_val += tmp_val;
                    }

                    /* Indicate ability to "view" */
                    if (!show_list)
                    {
                        out_val += " * to see,";
                        Button.button_add("[*]", '*');
                    }

                    /* Indicate legality of "toggle" */
                    if (use_inven)
                    {
                        out_val += " / for Inven,";
                        Button.button_add("[/]", '/');
                    }

                    /* Indicate legality of the "floor" */
                    if (allow_floor)
                    {
                        out_val += " - for floor,";
                        Button.button_add("[!]", '!');
                    }
                }

                /* Viewing floor */
                else
                {
                    /* Redraw if needed */
                    if (show_list)
                    {
                        show_floor(floor_list, floor_num, olist_mode);
                    }

                    /* Begin the prompt */
                    out_val = "Floor:";

                    /* List choices */
                    if (f1 <= f2)
                    {
                        /* Build the prompt */
                        tmp_val = String.Format(" {0}-{1}", Basic.I2A(f1), Basic.I2A(f2));

                        /* Append */
                        out_val += tmp_val;
                    }

                    /* Indicate ability to "view" */
                    if (!show_list)
                    {
                        out_val += " * to see,";
                        Button.button_add("[*]", '*');
                    }

                    /* Append */
                    if (use_inven)
                    {
                        out_val += " / for Inven,";
                        Button.button_add("[/]", '/');
                    }

                    /* Append */
                    else if (use_equip)
                    {
                        out_val += " / for Equip,";
                        Button.button_add("[/]", '/');
                    }
                }

                Misc.p_ptr.redraw_stuff();

                /* Finish the prompt */
                out_val += " ESC";

                /* Build the prompt */
                tmp_val = String.Format("({0}) {1}", out_val, pmt);

                /* Show the prompt */
                Utilities.prt(tmp_val, 0, 0);


                /* Get a key */
                which = Utilities.inkey();

                /* Parse it */
                switch (which.code)
                {
                case keycode_t.ESCAPE:
                {
                    done = true;
                    break;
                }

                case (keycode_t)'/':
                {
                    /* Toggle to inventory */
                    if (use_inven && (Misc.p_ptr.command_wrk != Misc.USE_INVEN))
                    {
                        Misc.p_ptr.command_wrk = Misc.USE_INVEN;
                    }

                    /* Toggle to equipment */
                    else if (use_equip && (Misc.p_ptr.command_wrk != Misc.USE_EQUIP))
                    {
                        Misc.p_ptr.command_wrk = Misc.USE_EQUIP;
                    }

                    /* No toggle allowed */
                    else
                    {
                        Utilities.bell("Cannot switch item selector!");
                        break;
                    }


                    /* Hack -- Fix screen */
                    if (show_list)
                    {
                        /* Load screen */
                        Utilities.screen_load();

                        /* Save screen */
                        Utilities.screen_save();
                    }

                    /* Need to redraw */
                    break;
                }

                case (keycode_t)'-':
                {
                    /* Paranoia */
                    if (!allow_floor)
                    {
                        Utilities.bell("Cannot select floor!");
                        break;
                    }

                    /* There is only one item */
                    if (floor_num == 1)
                    {
                        /* Auto-select */
                        if (Misc.p_ptr.command_wrk == (Misc.USE_FLOOR))
                        {
                            /* Special index */
                            k = 0 - floor_list[0];

                            /* Allow player to "refuse" certain actions */
                            if (!get_item_allow(k, cmdkey, is_harmless))
                            {
                                done = true;
                                break;
                            }

                            /* Accept that choice */
                            cp   = k;
                            item = true;
                            done = true;

                            break;
                        }
                    }

                    /* Hack -- Fix screen */
                    if (show_list)
                    {
                        /* Load screen */
                        Utilities.screen_load();

                        /* Save screen */
                        Utilities.screen_save();
                    }

                    Misc.p_ptr.command_wrk = (Misc.USE_FLOOR);

                    //#if 0
                    //                /* Check each legal object */
                    //                for (i = 0; i < floor_num; ++i)
                    //                {
                    //                    /* Special index */
                    //                    k = 0 - floor_list[i];

                    //                    /* Skip non-okay objects */
                    //                    if (!get_item_okay(k)) continue;

                    //                    /* Allow player to "refuse" certain actions */
                    //                    if (!get_item_allow(k, cmdkey, is_harmless)) continue;

                    //                    /* Accept that choice */
                    //                    (*cp) = k;
                    //                    item = true;
                    //                    done = true;
                    //                    break;
                    //                }
                    //#endif

                    break;
                }

                case (keycode_t)'0':
                case (keycode_t)'1':
                case (keycode_t)'2':
                case (keycode_t)'3':
                case (keycode_t)'4':
                case (keycode_t)'5':
                case (keycode_t)'6':
                case (keycode_t)'7':
                case (keycode_t)'8':
                case (keycode_t)'9':
                {
                    /* Look up the tag */
                    if (!get_tag(ref k, (char)which.code, cmd, quiver_tags))
                    {
                        Utilities.bell("Illegal object choice (tag)!");
                        break;
                    }

                    /* Hack -- Validate the item */
                    if ((k < Misc.INVEN_WIELD) ? !allow_inven : !allow_equip)
                    {
                        Utilities.bell("Illegal object choice (tag)!");
                        break;
                    }

                    /* Validate the item */
                    if (!get_item_okay(k))
                    {
                        Utilities.bell("Illegal object choice (tag)!");
                        break;
                    }

                    /* Allow player to "refuse" certain actions */
                    if (!get_item_allow(k, cmdkey, is_harmless))
                    {
                        done = true;
                        break;
                    }

                    /* Accept that choice */
                    cp   = k;
                    item = true;
                    done = true;
                    break;
                }

                case (keycode_t)'\n':
                case (keycode_t)'\r':
                {
                    /* Choose "default" inventory item */
                    if (Misc.p_ptr.command_wrk == Misc.USE_INVEN)
                    {
                        if (i1 != i2)
                        {
                            Utilities.bell("Illegal object choice (default)!");
                            break;
                        }

                        k = i1;
                    }

                    /* Choose the "default" slot (0) of the quiver */
                    else if (quiver_tags)
                    {
                        k = e1;
                    }

                    /* Choose "default" equipment item */
                    else if (Misc.p_ptr.command_wrk == Misc.USE_EQUIP)
                    {
                        if (e1 != e2)
                        {
                            Utilities.bell("Illegal object choice (default)!");
                            break;
                        }

                        k = e1;
                    }

                    /* Choose "default" floor item */
                    else
                    {
                        if (f1 != f2)
                        {
                            Utilities.bell("Illegal object choice (default)!");
                            break;
                        }

                        k = 0 - floor_list[f1];
                    }

                    /* Validate the item */
                    if (!get_item_okay(k))
                    {
                        Utilities.bell("Illegal object choice (default)!");
                        break;
                    }

                    /* Allow player to "refuse" certain actions */
                    if (!get_item_allow(k, cmdkey, is_harmless))
                    {
                        done = true;
                        break;
                    }

                    /* Accept that choice */
                    cp   = k;
                    item = true;
                    done = true;
                    break;
                }

                default:
                {
                    bool verify;

                    /* Note verify */
                    verify = (Char.IsUpper((char)which.code) ? true : false);

                    /* Lowercase */
                    which.code = (keycode_t)Char.ToLower((char)which.code);

                    /* Convert letter to inventory index */
                    if (Misc.p_ptr.command_wrk == Misc.USE_INVEN)
                    {
                        k = label_to_inven((char)which.code);

                        if (k < 0)
                        {
                            Utilities.bell("Illegal object choice (inven)!");
                            break;
                        }
                    }

                    /* Convert letter to equipment index */
                    else if (Misc.p_ptr.command_wrk == Misc.USE_EQUIP)
                    {
                        k = label_to_equip((char)which.code);

                        if (k < 0)
                        {
                            Utilities.bell("Illegal object choice (equip)!");
                            break;
                        }
                    }

                    /* Convert letter to floor index */
                    else
                    {
                        k = (Char.IsLower((char)which.code) ? Basic.A2I((char)which.code) : -1);

                        if (k < 0 || k >= floor_num)
                        {
                            Utilities.bell("Illegal object choice (floor)!");
                            break;
                        }

                        /* Special index */
                        k = 0 - floor_list[k];
                    }

                    /* Validate the item */
                    if (!get_item_okay(k))
                    {
                        Utilities.bell("Illegal object choice (normal)!");
                        break;
                    }

                    /* Verify the item */
                    if (verify && !verify_item("Try", k))
                    {
                        done = true;
                        break;
                    }

                    /* Allow player to "refuse" certain actions */
                    if (!get_item_allow(k, cmdkey, is_harmless))
                    {
                        done = true;
                        break;
                    }

                    /* Accept that choice */
                    cp   = k;
                    item = true;
                    done = true;
                    break;
                }
                }
            }


            /* Fix the screen if necessary */
            if (show_list)
            {
                /* Load screen */
                Utilities.screen_load();

                /* Hack -- Cancel "display" */
                show_list = false;
            }


            /* Kill buttons */
            Button.button_kill('*');
            Button.button_kill('/');
            Button.button_kill('-');
            Button.button_kill('!');
            Misc.p_ptr.redraw_stuff();

            /* Forget the item_tester_tval restriction */
            Misc.item_tester_tval = 0;

            /* Forget the item_tester_hook restriction */
            Misc.item_tester_hook = null;


            /* Toggle again if needed */
            if (toggle)
            {
                Command_Info.toggle_inven_equip();
            }

            /* Update */
            Misc.p_ptr.redraw |= (Misc.PR_INVEN | Misc.PR_EQUIP);
            Misc.p_ptr.redraw_stuff();


            /* Clear the prompt line */
            Utilities.prt("", 0, 0);

            /* Warning if needed */
            if (oops && str != null)
            {
                Utilities.msg("{0}", str);
            }

            /* Result */
            return(item);
        }