Example #1
0
        /*
         * Request a "movement" direction (1,2,3,4,6,7,8,9) from the user.
         *
         * Return true if a direction was chosen, otherwise return false.
         *
         * This function should be used for all "repeatable" commands, such as
         * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
         * as all commands which must reference a grid adjacent to the player,
         * and which may not reference the grid under the player.
         *
         * Directions "5" and "0" are illegal and will not be accepted.
         *
         * This function tracks and uses the "global direction", and uses
         * that as the "desired direction", if it is set.
         */
        public static bool get_rep_dir(out int dp)
        {
            int dir = 0;

            ui_event ke;

            /* Initialize */
            dp = 0;

            /* Get a direction */
            while (dir == 0)
            {
                /* Paranoia XXX XXX XXX */
                Utilities.message_flush();

                /* Get first keypress - the first test is to avoid displaying the
                 * prompt for direction if there's already a keypress queued up
                 * and waiting - this just avoids a flickering prompt if there is
                 * a "lazy" movement delay. */
                Utilities.inkey_scan = Misc.SCAN_INSTANT;
                ke = Utilities.inkey_ex();
                Utilities.inkey_scan = Misc.SCAN_OFF;

                if (ke.type == ui_event_type.EVT_NONE || (ke.type == ui_event_type.EVT_KBRD && Utilities.target_dir(ke.key) == 0))
                {
                    Utilities.prt("Direction or <click> (Escape to cancel)? ", 0, 0);
                    ke = Utilities.inkey_ex();
                }

                /* Check mouse coordinates */
                if (ke.type == ui_event_type.EVT_MOUSE)
                {
                    /*if (ke.button) */
                    {
                        int y    = Misc.KEY_GRID_Y(ke);
                        int x    = Misc.KEY_GRID_X(ke);
                        Loc from = new Loc(Misc.p_ptr.px, Misc.p_ptr.py);
                        Loc to   = new Loc(x, y);

                        throw new NotImplementedException();
                        //dir = pathfind_direction_to(from, to);
                    }
                }

                /* Get other keypresses until a direction is chosen. */
                else if (ke.type == ui_event_type.EVT_KBRD)
                {
                    int keypresses_handled = 0;

                    while (ke.type == ui_event_type.EVT_KBRD && ke.key.code != 0)
                    {
                        int this_dir;

                        if (ke.key.code == keycode_t.ESCAPE)
                        {
                            /* Clear the prompt */
                            Utilities.prt("", 0, 0);

                            return(false);
                        }

                        /* XXX Ideally show and move the cursor here to indicate
                         * the currently "Pending" direction. XXX */
                        this_dir = Utilities.target_dir(ke.key);

                        if (this_dir != 0)
                        {
                            dir = dir_transitions[dir][this_dir];
                        }

                        if (Misc.lazymove_delay == 0 || ++keypresses_handled > 1)
                        {
                            break;
                        }

                        Utilities.inkey_scan = Misc.lazymove_delay;
                        ke = Utilities.inkey_ex();
                    }

                    /* 5 is equivalent to "escape" */
                    if (dir == 5)
                    {
                        /* Clear the prompt */
                        Utilities.prt("", 0, 0);

                        return(false);
                    }
                }

                /* Oops */
                if (dir == 0)
                {
                    Utilities.bell("Illegal repeatable direction!");
                }
            }

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

            /* Save direction */
            dp = dir;

            /* Success */
            return(true);
        }
Example #2
0
 public item_selector_type(Command_Code a, string b, string c, Misc.item_tester_hook_func d, int e)
 {
     command = a;
     prompt = b;
     noop = c;
     filter = d;
     mode = e;
 }
Example #3
0
        /*
         * Determine the squelch level of an object, which is similar to its pseudo.
         *
         * The main point is when the value is undetermined given current info,
         * return the maximum possible value.
         */
        public static quality_squelch squelch_level_of(Object.Object o_ptr)
        {
            quality_squelch value = quality_squelch.SQUELCH_NONE;
            Bitflag         f     = new Bitflag(Object_Flag.SIZE);
            Bitflag         f2    = new Bitflag(Object_Flag.SIZE);
            int             i;

            o_ptr.object_flags_known(ref f);

            /* Deal with jewelry specially. */
            if (o_ptr.is_jewelry())
            {
                /* CC: average jewelry has at least one known positive pval */
                for (i = 0; i < o_ptr.num_pvals; i++)
                {
                    if ((o_ptr.this_pval_is_visible(i)) && (o_ptr.pval[i] > 0))
                    {
                        return(quality_squelch.SQUELCH_AVERAGE);
                    }
                }

                if ((o_ptr.to_h > 0) || (o_ptr.to_d > 0) || (o_ptr.to_a > 0))
                {
                    return(quality_squelch.SQUELCH_AVERAGE);
                }
                if ((o_ptr.attack_plusses_are_visible() &&
                     ((o_ptr.to_h < 0) || (o_ptr.to_d < 0))) ||
                    (o_ptr.defence_plusses_are_visible() && o_ptr.to_a < 0))
                {
                    return(quality_squelch.SQUELCH_BAD);
                }

                return(quality_squelch.SQUELCH_AVERAGE);
            }

            /* And lights */
            if (o_ptr.tval == TVal.TV_LIGHT)
            {
                Object_Flag.create_mask(f2, true, Object_Flag.object_flag_id.WIELD);
                if (f.is_inter(f2))
                {
                    return(quality_squelch.SQUELCH_ALL);
                }
                if ((o_ptr.to_h > 0) || (o_ptr.to_d > 0) || (o_ptr.to_a > 0))
                {
                    return(quality_squelch.SQUELCH_GOOD);
                }
                if ((o_ptr.to_h < 0) || (o_ptr.to_d < 0) || (o_ptr.to_a < 0))
                {
                    return(quality_squelch.SQUELCH_BAD);
                }

                return(quality_squelch.SQUELCH_AVERAGE);
            }

            /* CC: we need to redefine "bad" with multiple pvals
             * At the moment we use "all pvals known and negative" */
            for (i = 0; i < o_ptr.num_pvals; i++)
            {
                if (!o_ptr.this_pval_is_visible(i) ||
                    (o_ptr.pval[i] > 0))
                {
                    break;
                }

                if (i == (o_ptr.num_pvals - 1))
                {
                    return(quality_squelch.SQUELCH_BAD);
                }
            }

            if (o_ptr.was_sensed())
            {
                Object.Object.obj_pseudo_t pseudo = o_ptr.pseudo();

                switch (pseudo)
                {
                case Object.Object.obj_pseudo_t.INSCRIP_AVERAGE: {
                    value = quality_squelch.SQUELCH_AVERAGE;
                    break;
                }

                case Object.Object.obj_pseudo_t.INSCRIP_EXCELLENT: {
                    /* have to assume splendid until you have tested it */
                    if (o_ptr.was_worn())
                    {
                        if (o_ptr.high_resist_is_possible())
                        {
                            value = quality_squelch.SQUELCH_EXCELLENT_NO_SPL;
                        }
                        else
                        {
                            value = quality_squelch.SQUELCH_EXCELLENT_NO_HI;
                        }
                    }
                    else
                    {
                        value = quality_squelch.SQUELCH_ALL;
                    }
                    break;
                }

                case Object.Object.obj_pseudo_t.INSCRIP_SPLENDID:
                    value = quality_squelch.SQUELCH_ALL;
                    break;

                case Object.Object.obj_pseudo_t.INSCRIP_null:
                case Object.Object.obj_pseudo_t.INSCRIP_SPECIAL:
                    value = quality_squelch.SQUELCH_MAX;
                    break;

                /* This is the interesting case */
                case Object.Object.obj_pseudo_t.INSCRIP_STRANGE:
                case Object.Object.obj_pseudo_t.INSCRIP_MAGICAL: {
                    value = quality_squelch.SQUELCH_GOOD;

                    if ((o_ptr.attack_plusses_are_visible() ||
                         Random.randcalc_valid(o_ptr.kind.to_h, o_ptr.to_h) ||
                         Random.randcalc_valid(o_ptr.kind.to_d, o_ptr.to_d)) &&
                        (o_ptr.defence_plusses_are_visible() ||
                         Random.randcalc_valid(o_ptr.kind.to_a, o_ptr.to_a)))
                    {
                        int isgood = is_object_good(o_ptr);
                        if (isgood > 0)
                        {
                            value = quality_squelch.SQUELCH_GOOD;
                        }
                        else if (isgood < 0)
                        {
                            value = quality_squelch.SQUELCH_BAD;
                        }
                        else
                        {
                            value = quality_squelch.SQUELCH_AVERAGE;
                        }
                    }
                    break;
                }

                default:
                    /* do not handle any other possible pseudo values */
                    Misc.assert(false);
                    break;
                }
            }
            else
            {
                if (o_ptr.was_worn())
                {
                    value = quality_squelch.SQUELCH_EXCELLENT_NO_SPL;             /* object would be sensed if it were splendid */
                }
                else if (o_ptr.is_known_not_artifact())
                {
                    value = quality_squelch.SQUELCH_ALL;
                }
                else
                {
                    value = quality_squelch.SQUELCH_MAX;
                }
            }

            return(value);
        }
Example #4
0
        //size = panel.Length
        static int get_panel(int oid, ref Data_Panel[] panel)
        {
            int        size = panel.Length;
            int        ret  = panel.Length;
            Type_Union END  = new Type_Union();

            Player.Player p_ptr  = Player.Player.instance;
            Player_Other  op_ptr = Player_Other.instance;

            switch (oid)
            {
            case 1: {
                int i = 0;
                Misc.assert(size >= (uint)boundaries[1].page_rows);
                ret = boundaries[1].page_rows;
                P_I(ConsoleColor.Cyan, "Name", "{0}", new Type_Union(op_ptr.full_name), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Sex", "{0}", new Type_Union(p_ptr.Sex.Title), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Race", "{0}", new Type_Union(p_ptr.Race.Name), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Class", "{0}", new Type_Union(p_ptr.Class.Name), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Title", "{0}", new Type_Union(show_title()), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "HP", "{0}/{1}", new Type_Union(p_ptr.chp), new Type_Union(p_ptr.mhp), panel, ref i);
                P_I(ConsoleColor.Cyan, "SP", "{0}/{1}", new Type_Union(p_ptr.csp), new Type_Union(p_ptr.msp), panel, ref i);
                P_I(ConsoleColor.Cyan, "Level", "{0}", new Type_Union(p_ptr.lev), END, panel, ref i);
                Misc.assert(i == boundaries[1].page_rows);
                return(ret);
            }

            case 2: {
                int i = 0;
                Misc.assert(ret >= boundaries[2].page_rows);
                ret = boundaries[2].page_rows;
                P_I(max_color(p_ptr.lev, p_ptr.max_lev), "Level", "{0}", new Type_Union(p_ptr.lev), END, panel, ref i);
                P_I(max_color(p_ptr.exp, p_ptr.max_exp), "Cur Exp", "{0}", new Type_Union(p_ptr.exp), END, panel, ref i);
                P_I(ConsoleColor.Green, "Max Exp", "{0}", new Type_Union(p_ptr.max_exp), END, panel, ref i);
                P_I(ConsoleColor.Green, "Adv Exp", "{0}", new Type_Union(show_adv_exp()), END, panel, ref i);
                P_I(ConsoleColor.Green, "MaxDepth", "{0}", new Type_Union(show_depth()), END, panel, ref i);
                P_I(ConsoleColor.Green, "Game Turns", "{0}", new Type_Union(Misc.turn), END, panel, ref i);
                P_I(ConsoleColor.Green, "Standard Turns", "{0}", new Type_Union((int)(p_ptr.total_energy / 100)), END, panel, ref i);
                P_I(ConsoleColor.Green, "Resting Turns", "{0}", new Type_Union((int)(p_ptr.resting_turn)), END, panel, ref i);
                P_I(ConsoleColor.Green, "Gold", "{0}", new Type_Union(p_ptr.au), END, panel, ref i);
                Misc.assert(i == boundaries[2].page_rows);
                return(ret);
            }

            case 3: {
                int i = 0;
                Misc.assert(ret >= boundaries[3].page_rows);
                ret = boundaries[3].page_rows;
                P_I(ConsoleColor.Cyan, "Armor", "[{0},%+y]", new Type_Union(p_ptr.state.dis_ac),
                    new Type_Union(p_ptr.state.dis_to_a), panel, ref i);
                P_I(ConsoleColor.Cyan, "Fight", "(%+y,%+y)", new Type_Union(p_ptr.state.dis_to_h),
                    new Type_Union(p_ptr.state.dis_to_d), panel, ref i);
                P_I(ConsoleColor.Cyan, "Melee", "{0}", new Type_Union(show_melee_weapon(p_ptr.inventory[Misc.INVEN_WIELD])), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Shoot", "{0}", new Type_Union(show_missile_weapon(p_ptr.inventory[Misc.INVEN_BOW])), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Blows", "{0}.%y/turn", new Type_Union(p_ptr.state.num_blows / 100),
                    new Type_Union((p_ptr.state.num_blows / 10) % 10), panel, ref i);
                P_I(ConsoleColor.Cyan, "Shots", "{0}/turn", new Type_Union(p_ptr.state.num_shots), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Infra", "{0} ft", new Type_Union(p_ptr.state.see_infra * 10), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Speed", "{0}", new Type_Union(show_speed()), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Burden", "%.1y lbs", new Type_Union(p_ptr.total_weight / 10.0f), END, panel, ref i);
                Misc.assert(i == boundaries[3].page_rows);
                return(ret);
            }

            case 4: {
                temp_skills[] skills =
                {
                    new temp_skills("Saving Throw", Skill.SAVE,              6),
                    new temp_skills("Stealth",      Skill.STEALTH,           1),
                    new temp_skills("Fighting",     Skill.TO_HIT_MELEE,     12),
                    new temp_skills("Shooting",     Skill.TO_HIT_BOW,       12),
                    new temp_skills("Disarming",    Skill.DISARM,            8),
                    new temp_skills("Magic Device", Skill.DEVICE,            6),
                    new temp_skills("Perception",   Skill.SEARCH_FREQUENCY,  6),
                    new temp_skills("Searching",    Skill.SEARCH, 6)
                };
                int i;
                Misc.assert(skills.Length == boundaries[4].page_rows);
                ret = skills.Length;
                if (ret > size)
                {
                    ret = size;
                }
                for (i = 0; i < ret; i++)
                {
                    short skill = p_ptr.state.skills[(int)skills[i].skill];
                    panel[i].color = ConsoleColor.Cyan;
                    panel[i].label = skills[i].name;
                    if (skills[i].skill == Skill.SAVE || skills[i].skill == Skill.SEARCH)
                    {
                        if (skill < 0)
                        {
                            skill = 0;
                        }
                        if (skill > 100)
                        {
                            skill = 100;
                        }
                        panel[i].fmt      = "{0}%";
                        panel[i].value[0] = new Type_Union(skill);
                        panel[i].color    = colour_table[skill / 10];
                    }
                    else if (skills[i].skill == Skill.DEVICE)
                    {
                        panel[i].fmt      = "{0}";
                        panel[i].value[0] = new Type_Union(skill);
                        panel[i].color    = colour_table[skill / 13];
                    }
                    else if (skills[i].skill == Skill.SEARCH_FREQUENCY)
                    {
                        if (skill <= 0)
                        {
                            skill = 1;
                        }
                        if (skill >= 50)
                        {
                            panel[i].fmt   = "1 in 1";
                            panel[i].color = colour_table[10];
                        }
                        else
                        {
                            /* convert to % chance of searching */
                            skill             = (short)(50 - skill);
                            panel[i].fmt      = "1 in {0}";
                            panel[i].value[0] = new Type_Union(skill);
                            panel[i].color    = colour_table[(100 - skill * 2) / 10];
                        }
                    }
                    else if (skills[i].skill == Skill.DISARM)
                    {
                        /* assume disarming a dungeon trap */
                        skill -= 5;
                        if (skill > 100)
                        {
                            skill = 100;
                        }
                        if (skill < 2)
                        {
                            skill = 2;
                        }
                        panel[i].fmt      = "{0}%";
                        panel[i].value[0] = new Type_Union(skill);
                        panel[i].color    = colour_table[skill / 10];
                    }
                    else
                    {
                        panel[i].fmt = "{0}";
                        //last argument for likert was "panel[i].color"...
                        ConsoleColor c = ConsoleColor.DarkMagenta;                                         //Random color...
                        panel[i].value[0] = new Type_Union(likert(skill, skills[i].div, ref c));
                    }
                }
                return(ret);
            }

            case 5: {
                int i = 0;
                Misc.assert(ret >= boundaries[5].page_rows);
                ret = boundaries[5].page_rows;
                P_I(ConsoleColor.Cyan, "Age", "{0}", new Type_Union(p_ptr.age), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Height", "{0}", new Type_Union(p_ptr.ht), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Weight", "{0}", new Type_Union(p_ptr.wt), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Social", "{0}", new Type_Union(show_status()), END, panel, ref i);
                P_I(ConsoleColor.Cyan, "Maximize", "{0}", new Type_Union(Option.birth_maximize.value ? 'Y' : 'N'), END, panel, ref i);
                //#if 0
                //    /* Preserve mode deleted */
                //    P_I(ConsoleColor.Cyan, "Preserve",	"{0}",	c2u(birth_preserve ? 'Y' : 'N'), END);
                //#endif
                Misc.assert(i == boundaries[5].page_rows);
                return(ret);
            }
            }
            /* hopefully not reached */
            return(0);
        }