Esempio n. 1
0
        /*** Pickup ***/

        /*
         * Pickup all gold at the player's current location.
         */
        static void py_pickup_gold()
        {
            int py = Misc.p_ptr.py;
            int px = Misc.p_ptr.px;

            int total_gold = 0;

            byte[] treasure;

            short this_o_idx = 0;
            short next_o_idx = 0;

            Object.Object o_ptr;

            Message_Type sound_msg;
            bool         verbal = false;

            /* Allocate an array of ordinary gold objects */
            treasure = new byte[(int)Object.SVal.sval_gold.SV_GOLD_MAX];


            /* Pick up all the ordinary gold objects */
            for (this_o_idx = Cave.cave.o_idx[py][px]; this_o_idx != 0; this_o_idx = next_o_idx)
            {
                /* Get the object */
                o_ptr = Object.Object.byid(this_o_idx);
                if (o_ptr == null)
                {
                    break;
                }

                /* Get the next object */
                next_o_idx = o_ptr.next_o_idx;

                /* Ignore if not legal treasure */
                if ((o_ptr.tval != TVal.TV_GOLD) ||
                    (o_ptr.sval >= (int)SVal.sval_gold.SV_GOLD_MAX))
                {
                    continue;
                }

                /* Note that we have this kind of treasure */
                treasure[o_ptr.sval]++;

                /* Remember whether feedback message is in order */
                if (!Squelch.item_ok(o_ptr))
                {
                    verbal = true;
                }

                /* Increment total value */
                total_gold += (int)o_ptr.pval[Misc.DEFAULT_PVAL];

                /* Delete the gold */
                Object.Object.delete_object_idx(this_o_idx);
            }

            /* Pick up the gold, if present */
            if (total_gold != 0)
            {
                //char buf[1024];
                //char tmp[80];
                string      buf;
                string      tmp;
                int         i, count, total;
                Object_Kind kind;

                /* Build a message */
                buf = String.Format("You have found {0} gold pieces worth of ", total_gold);

                /* Count the types of treasure present */
                for (total = 0, i = 0; i < (int)SVal.sval_gold.SV_GOLD_MAX; i++)
                {
                    if (treasure[i] != 0)
                    {
                        total++;
                    }
                }

                /* List the treasure types */
                for (count = 0, i = 0; i < (int)SVal.sval_gold.SV_GOLD_MAX; i++)
                {
                    /* Skip if no treasure of this type */
                    if (treasure[i] == 0)
                    {
                        continue;
                    }

                    /* Get this object index */
                    kind = Object_Kind.lookup_kind(TVal.TV_GOLD, i);
                    if (kind == null)
                    {
                        continue;
                    }

                    /* Get the object name */
                    tmp = Object.Object.object_kind_name(kind, true);

                    /* Build up the pickup string */
                    buf = buf + tmp;

                    /* Added another kind of treasure */
                    count++;

                    /* Add a comma if necessary */
                    if ((total > 2) && (count < total))
                    {
                        buf += ",";
                    }

                    /* Add an "and" if necessary */
                    if ((total >= 2) && (count == total - 1))
                    {
                        buf += " and";
                    }

                    /* Add a space or period if necessary */
                    if (count < total)
                    {
                        buf += " ";
                    }
                    else
                    {
                        buf += ".";
                    }
                }

                /* Determine which sound to play */
                if (total_gold < 200)
                {
                    sound_msg = Message_Type.MSG_MONEY1;
                }
                else if (total_gold < 600)
                {
                    sound_msg = Message_Type.MSG_MONEY2;
                }
                else
                {
                    sound_msg = Message_Type.MSG_MONEY3;
                }

                /* Display the message */
                if (verbal)
                {
                    Utilities.msgt(sound_msg, "{0}", buf);
                }

                /* Add gold to purse */
                Misc.p_ptr.au += total_gold;

                /* Redraw gold */
                Misc.p_ptr.redraw |= (Misc.PR_GOLD);
            }

            /* Free the gold array */
            //FREE(treasure);
        }
Esempio n. 2
0
        /*
         * Update the current "run" path
         *
         * Return true if the running should be stopped
         */
        static bool run_test()
        {
            int py = Misc.p_ptr.py;
            int px = Misc.p_ptr.px;

            int prev_dir;
            int new_dir;

            int  row, col;
            int  i, max;
            bool inv;
            int  option, option2;


            /* No options yet */
            option  = 0;
            option2 = 0;

            /* Where we came from */
            prev_dir = Misc.p_ptr.run_old_dir;


            /* Range of newly adjacent grids */
            max = (prev_dir & 0x01) + 1;


            /* Look at every newly adjacent square. */
            for (i = -max; i <= max; i++)
            {
                Object.Object o_ptr;


                /* New direction */
                new_dir = cycle[chome[prev_dir] + i];

                /* New location */
                row = py + Misc.ddy[new_dir];
                col = px + Misc.ddx[new_dir];


                /* Visible monsters abort running */
                if (Cave.cave.m_idx[row][col] > 0)
                {
                    Monster.Monster m_ptr = Cave.cave_monster(Cave.cave, Cave.cave.m_idx[row][col]);

                    /* Visible monster */
                    if (m_ptr.ml)
                    {
                        return(true);
                    }
                }

                /* Visible objects abort running */
                for (o_ptr = Object.Object.get_first_object(row, col); o_ptr != null; o_ptr = Object.Object.get_next_object(o_ptr))
                {
                    /* Visible object */
                    if (o_ptr.marked != 0 && !Squelch.item_ok(o_ptr))
                    {
                        return(true);
                    }
                }


                /* Assume unknown */
                inv = true;

                /* Check memorized grids */
                if ((Cave.cave.info[row][col] & (Cave.CAVE_MARK)) != 0)
                {
                    bool notice = true;

                    /* Examine the terrain */
                    switch (Cave.cave.feat[row][col])
                    {
                    /* Floors */
                    case Cave.FEAT_FLOOR:

                    /* Invis traps */
                    case Cave.FEAT_INVIS:

                    /* Secret doors */
                    case Cave.FEAT_SECRET:

                    /* Normal veins */
                    case Cave.FEAT_MAGMA:
                    case Cave.FEAT_QUARTZ:

                    /* Hidden treasure */
                    case Cave.FEAT_MAGMA_H:
                    case Cave.FEAT_QUARTZ_H:

                    /* Walls */
                    case Cave.FEAT_WALL_EXTRA:
                    case Cave.FEAT_WALL_INNER:
                    case Cave.FEAT_WALL_OUTER:
                    case Cave.FEAT_WALL_SOLID:
                    case Cave.FEAT_PERM_EXTRA:
                    case Cave.FEAT_PERM_INNER:
                    case Cave.FEAT_PERM_OUTER:
                    case Cave.FEAT_PERM_SOLID:
                    {
                        /* Ignore */
                        notice = false;

                        /* Done */
                        break;
                    }
                    }

                    /* Interesting feature */
                    if (notice)
                    {
                        return(true);
                    }

                    /* The grid is "visible" */
                    inv = false;
                }

                /* Analyze unknown grids and floors */
                if (inv || Cave.cave_floor_bold(row, col))
                {
                    /* Looking for open area */
                    if (Misc.p_ptr.run_open_area)
                    {
                        /* Nothing */
                    }

                    /* The first new direction. */
                    else if (option == 0)
                    {
                        option = new_dir;
                    }

                    /* Three new directions. Stop running. */
                    else if (option2 != 0)
                    {
                        return(true);
                    }

                    /* Two non-adjacent new directions.  Stop running. */
                    else if (option != cycle[chome[prev_dir] + i - 1])
                    {
                        return(true);
                    }

                    /* Two new (adjacent) directions (case 1) */
                    else if ((new_dir & 0x01) != 0)
                    {
                        option2 = new_dir;
                    }

                    /* Two new (adjacent) directions (case 2) */
                    else
                    {
                        option2 = option;
                        option  = new_dir;
                    }
                }

                /* Obstacle, while looking for open area */
                else
                {
                    if (Misc.p_ptr.run_open_area)
                    {
                        if (i < 0)
                        {
                            /* Break to the right */
                            Misc.p_ptr.run_break_right = true;
                        }

                        else if (i > 0)
                        {
                            /* Break to the left */
                            Misc.p_ptr.run_break_left = true;
                        }
                    }
                }
            }


            /* Look at every soon to be newly adjacent square. */
            for (i = -max; i <= max; i++)
            {
                /* New direction */
                new_dir = cycle[chome[prev_dir] + i];

                /* New location */
                row = py + Misc.ddy[prev_dir] + Misc.ddy[new_dir];
                col = px + Misc.ddx[prev_dir] + Misc.ddx[new_dir];

                /* HACK: Ugh. Sometimes we come up with illegal bounds. This will
                 * treat the symptom but not the disease. */
                if (row >= Cave.DUNGEON_HGT || col >= Cave.DUNGEON_WID)
                {
                    continue;
                }
                if (row < 0 || col < 0)
                {
                    continue;
                }

                /* Visible monsters abort running */
                if (Cave.cave.m_idx[row][col] > 0)
                {
                    Monster.Monster m_ptr = Cave.cave_monster(Cave.cave, Cave.cave.m_idx[row][col]);

                    /* Visible monster */
                    if (m_ptr.ml)
                    {
                        return(true);
                    }
                }
            }

            /* Looking for open area */
            if (Misc.p_ptr.run_open_area)
            {
                /* Hack -- look again */
                for (i = -max; i < 0; i++)
                {
                    new_dir = cycle[chome[prev_dir] + i];

                    row = py + Misc.ddy[new_dir];
                    col = px + Misc.ddx[new_dir];

                    /* Unknown grid or non-wall */
                    /* Was: cave_floor_bold(row, col) */
                    if ((Cave.cave.info[row][col] & (Cave.CAVE_MARK)) == 0 ||
                        (Cave.cave.feat[row][col] < Cave.FEAT_SECRET))
                    {
                        /* Looking to break right */
                        if (Misc.p_ptr.run_break_right)
                        {
                            return(true);
                        }
                    }

                    /* Obstacle */
                    else
                    {
                        /* Looking to break left */
                        if (Misc.p_ptr.run_break_left)
                        {
                            return(true);
                        }
                    }
                }

                /* Hack -- look again */
                for (i = max; i > 0; i--)
                {
                    new_dir = cycle[chome[prev_dir] + i];

                    row = py + Misc.ddy[new_dir];
                    col = px + Misc.ddx[new_dir];

                    /* Unknown grid or non-wall */
                    /* Was: cave_floor_bold(row, col) */
                    if ((Cave.cave.info[row][col] & (Cave.CAVE_MARK)) == 0 ||
                        (Cave.cave.feat[row][col] < Cave.FEAT_SECRET))
                    {
                        /* Looking to break left */
                        if (Misc.p_ptr.run_break_left)
                        {
                            return(true);
                        }
                    }

                    /* Obstacle */
                    else
                    {
                        /* Looking to break right */
                        if (Misc.p_ptr.run_break_right)
                        {
                            return(true);
                        }
                    }
                }
            }


            /* Not looking for open area */
            else
            {
                /* No options */
                if (option == 0)
                {
                    return(true);
                }

                /* One option */
                else if (option2 == 0)
                {
                    /* Primary option */
                    Misc.p_ptr.run_cur_dir = (short)option;

                    /* No other options */
                    Misc.p_ptr.run_old_dir = (short)option;
                }

                /* Two options, examining corners */
                else
                {
                    /* Primary option */
                    Misc.p_ptr.run_cur_dir = (short)option;

                    /* Hack -- allow curving */
                    Misc.p_ptr.run_old_dir = (short)option2;
                }
            }


            /* About to hit a known wall, stop */
            if (see_wall(Misc.p_ptr.run_cur_dir, py, px))
            {
                return(true);
            }


            /* Failure */
            return(false);
        }
Esempio n. 3
0
        public static int do_autopickup()
        {
            int py = Misc.p_ptr.py;
            int px = Misc.p_ptr.px;

            short this_o_idx, next_o_idx = 0;

            Object.Object o_ptr;

            /* Objects picked up.  Used to determine time cost of command. */
            byte objs_picked_up = 0;

            int floor_num = 0;

            int[] floor_list = new int[Misc.MAX_FLOOR_STACK + 1];

            /* Nothing to pick up -- return */
            if (Cave.cave.o_idx[py][px] == 0)
            {
                return(0);
            }

            /* Always pickup gold, effortlessly */
            py_pickup_gold();


            /* Scan the remaining objects */
            for (this_o_idx = Cave.cave.o_idx[py][px]; this_o_idx != 0; this_o_idx = next_o_idx)
            {
                /* Get the object and the next object */
                o_ptr = Object.Object.byid(this_o_idx);
                if (o_ptr == null)
                {
                    break;
                }
                next_o_idx = o_ptr.next_o_idx;

                /* Ignore all hidden objects and non-objects */
                if (Squelch.item_ok(o_ptr) || o_ptr.kind == null)
                {
                    continue;
                }

                /* XXX Hack -- Enforce limit */
                if (floor_num >= floor_list.Length)
                {
                    break;
                }


                /* Hack -- disturb */
                Cave.disturb(Misc.p_ptr, 0, 0);

                throw new NotImplementedException();
                ///* Automatically pick up items into the backpack */
                //if (auto_pickup_okay(o_ptr))
                //{
                //    /* Pick up the object with message */
                //    py_pickup_aux(this_o_idx, true);
                //    objs_picked_up++;

                //    continue;
                //}


                ///* Tally objects and store them in an array. */

                ///* Remember this object index */
                //floor_list[floor_num] = this_o_idx;

                ///* Count non-gold objects that remain on the floor. */
                //floor_num++;
            }

            return(objs_picked_up);
        }