Example #1
0
        /*
         * Checks for additional knowledge implied by what the player already knows.
         *
         * \param o_ptr is the object to check
         *
         * returns whether it calls object_notice_everyting
         */
        bool check_for_ident()
        {
            Bitflag flags       = new Bitflag(Object_Flag.SIZE);
            Bitflag known_flags = new Bitflag(Object_Flag.SIZE);
            Bitflag f2          = new Bitflag(Object_Flag.SIZE);

            object_flags(ref flags);
            object_flags_known(ref known_flags);

            /* Some flags are irrelevant or never learned or too hard to learn */
            Object_Flag.create_mask(f2, false, Object_Flag.object_flag_type.INT,
                                    Object_Flag.object_flag_type.IGNORE,
                                    Object_Flag.object_flag_type.HATES);

            flags.diff(f2);
            known_flags.diff(f2);

            if (!flags.is_equal(known_flags))
            {
                return(false);
            }

            /* If we know attack bonuses, and defence bonuses, and effect, then
             * we effectively know everything, so mark as such */
            if ((attack_plusses_are_visible() || (was_sensed() && to_h == 0 && to_d == 0)) &&
                (defence_plusses_are_visible() || (was_sensed() && to_a == 0)) &&
                (effect_is_known() || effect() == null))
            {
                /* In addition to knowing the pval flags, it is necessary to know the pvals to know everything */
                int i;
                for (i = 0; i < num_pvals; i++)
                {
                    if (!this_pval_is_visible(i))
                    {
                        break;
                    }
                }
                if (i == num_pvals)
                {
                    notice_everything();
                    return(true);
                }
            }

            /* We still know all the flags, so we still know if it's an ego */
            if (ego != null)
            {
                /* require worn status so you don't learn launcher of accuracy or gloves of slaying before wield */
                if (was_worn())
                {
                    notice_ego();
                }
            }

            return(false);
        }
Example #2
0
        /**
         * Fill in a value in the slay cache. Return true if a change is made.
         *
         * \param index is the set of slay flags whose value we are adding
         * \param value is the value of the slay flags in index
         */
        public static bool fill_slay_cache(Bitflag index, int value)
        {
            for (int i = 0; !slay_cache[i].flags.is_empty(); i++)
            {
                if (index.is_equal(slay_cache[i].flags))
                {
                    slay_cache[i].value = value;
                    return(true);
                }
            }

            return(false);
        }
Example #3
0
        /**
         * Check the slay cache for a combination of slays and return a slay value
         *
         * \param index is the set of slay flags to look for
         */
        //index might be an array
        public static int check_slay_cache(Bitflag index)
        {
            int i;

            for (i = 0; !slay_cache[i].flags.is_empty(); i++)
            {
                if (index.is_equal(slay_cache[i].flags))
                {
                    break;
                }
            }

            return(slay_cache[i].value);
        }
Example #4
0
        /*
         * Checks for additional knowledge implied by what the player already knows.
         *
         * \param o_ptr is the object to check
         *
         * returns whether it calls object_notice_everyting
         */
        bool check_for_ident()
        {
            Bitflag flags = new Bitflag(Object_Flag.SIZE);
            Bitflag known_flags = new Bitflag(Object_Flag.SIZE);
            Bitflag f2 = new Bitflag(Object_Flag.SIZE);

            object_flags(ref flags);
            object_flags_known(ref known_flags);

            /* Some flags are irrelevant or never learned or too hard to learn */
            Object_Flag.create_mask(f2, false,	Object_Flag.object_flag_type.INT,
                                                Object_Flag.object_flag_type.IGNORE,
                                                Object_Flag.object_flag_type.HATES);

            flags.diff(f2);
            known_flags.diff(f2);

            if (!flags.is_equal(known_flags)) return false;

            /* If we know attack bonuses, and defence bonuses, and effect, then
             * we effectively know everything, so mark as such */
            if ((attack_plusses_are_visible() || (was_sensed() && to_h == 0 && to_d == 0)) &&
                (defence_plusses_are_visible() || (was_sensed() && to_a == 0)) &&
                (effect_is_known() || effect() == null))
            {
                /* In addition to knowing the pval flags, it is necessary to know the pvals to know everything */
                int i;
                for (i = 0; i < num_pvals; i++)
                    if (!this_pval_is_visible(i))
                        break;
                if (i == num_pvals) {
                    notice_everything();
                    return true;
                }
            }

            /* We still know all the flags, so we still know if it's an ego */
            if (ego != null)
            {
                /* require worn status so you don't learn launcher of accuracy or gloves of slaying before wield */
                if (was_worn())
                    notice_ego();
            }

            return false;
        }
Example #5
0
        /**
         * Create a cache of slay combinations found on ego items, and the values of
         * these combinations. This is to speed up slay_power(), which will be called
         * many times for ego items during the game.
         *
         * \param items is the set of ego types from which we are extracting slay
         * combinations
         */
        public static int create_slay_cache(Ego_Item[] items)
        {
            int     count     = 0;
            Bitflag cacheme   = new Bitflag(Object_Flag.SIZE);
            Bitflag slay_mask = new Bitflag(Object_Flag.SIZE);

            /* Build the slay mask */
            Object_Flag.create_mask(slay_mask, false, Object_Flag.object_flag_type.SLAY,
                                    Object_Flag.object_flag_type.KILL, Object_Flag.object_flag_type.BRAND);

            /* Calculate necessary size of slay_cache */
            Bitflag[] dupcheck = new Bitflag[Misc.z_info.e_max];

            for (int i = 0; i < Misc.z_info.e_max; i++)
            {
                dupcheck[i] = new Bitflag(Object_Flag.SIZE);
                Ego_Item e_ptr = items[i];

                //Some items are null... I guess we should just skip them...?
                //TODO: Find out why they are null, and see if we actually should just skip them...
                if (e_ptr == null)
                {
                    continue;
                }

                /* Find the slay flags on this ego */
                cacheme.copy(e_ptr.flags);
                cacheme.inter(slay_mask);

                /* Only consider non-empty combinations of slay flags */
                if (!cacheme.is_empty())
                {
                    /* Skip previously scanned combinations */
                    for (int j = 0; j < i; j++)
                    {
                        if (cacheme.is_equal(dupcheck[j]))
                        {
                            continue;
                        }
                    }

                    /* msg("Found a new slay combo on an ego item"); */
                    count++;
                    dupcheck[i].copy(cacheme);
                }
            }

            /* Allocate slay_cache with an extra empty element for an iteration stop */
            slay_cache = new flag_cache[count + 1];
            count      = 0;

            /* Populate the slay_cache */
            for (int i = 0; i < Misc.z_info.e_max; i++)
            {
                if (!dupcheck[i].is_empty())
                {
                    slay_cache[count] = new flag_cache();
                    slay_cache[count].flags.copy(dupcheck[i]);
                    slay_cache[count].value = 0;
                    count++;
                    /*msg("Cached a slay combination");*/
                }
            }

            //From a time without garbage collection...

            /*for (i = 0; i < z_info.e_max; i++)
             *  FREE(dupcheck[i]);
             * FREE(dupcheck);*/

            /* Success */
            return(0);
        }
Example #6
0
        /**
         * Fill in a value in the slay cache. Return true if a change is made.
         *
         * \param index is the set of slay flags whose value we are adding
         * \param value is the value of the slay flags in index
         */
        public static bool fill_slay_cache(Bitflag index, int value)
        {
            for (int i = 0; !slay_cache[i].flags.is_empty(); i++) {
                if (index.is_equal(slay_cache[i].flags)) {
                    slay_cache[i].value = value;
                    return true;
                }
            }

            return false;
        }
Example #7
0
        /**
         * Create a cache of slay combinations found on ego items, and the values of
         * these combinations. This is to speed up slay_power(), which will be called
         * many times for ego items during the game.
         *
         * \param items is the set of ego types from which we are extracting slay
         * combinations
         */
        public static int create_slay_cache(Ego_Item[] items)
        {
            int count = 0;
            Bitflag cacheme = new Bitflag(Object_Flag.SIZE);
            Bitflag slay_mask = new Bitflag(Object_Flag.SIZE);

            /* Build the slay mask */
            Object_Flag.create_mask(slay_mask, false, Object_Flag.object_flag_type.SLAY,
                Object_Flag.object_flag_type.KILL, Object_Flag.object_flag_type.BRAND);

            /* Calculate necessary size of slay_cache */
            Bitflag[] dupcheck = new Bitflag[Misc.z_info.e_max];

            for (int i = 0; i < Misc.z_info.e_max; i++) {
                dupcheck[i] = new Bitflag(Object_Flag.SIZE);
                Ego_Item e_ptr = items[i];

                //Some items are null... I guess we should just skip them...?
                //TODO: Find out why they are null, and see if we actually should just skip them...
                if(e_ptr == null) {
                    continue;
                }

                /* Find the slay flags on this ego */
                cacheme.copy(e_ptr.flags);
                cacheme.inter(slay_mask);

                /* Only consider non-empty combinations of slay flags */
                if (!cacheme.is_empty()) {
                    /* Skip previously scanned combinations */
                    for (int j = 0; j < i; j++)
                        if (cacheme.is_equal(dupcheck[j])) continue;

                    /* msg("Found a new slay combo on an ego item"); */
                    count++;
                    dupcheck[i].copy(cacheme);
                }
            }

            /* Allocate slay_cache with an extra empty element for an iteration stop */
            slay_cache = new flag_cache[count + 1];
            count = 0;

            /* Populate the slay_cache */
            for (int i = 0; i < Misc.z_info.e_max; i++) {
                if (!dupcheck[i].is_empty()) {
                    slay_cache[count] = new flag_cache();
                    slay_cache[count].flags.copy(dupcheck[i]);
                    slay_cache[count].value = 0;
                    count++;
                    /*msg("Cached a slay combination");*/
                }
            }

            //From a time without garbage collection...
            /*for (i = 0; i < z_info.e_max; i++)
                FREE(dupcheck[i]);
            FREE(dupcheck);*/

            /* Success */
            return 0;
        }
Example #8
0
        /**
         * Check the slay cache for a combination of slays and return a slay value
         *
         * \param index is the set of slay flags to look for
         */
        //index might be an array
        public static int check_slay_cache(Bitflag index)
        {
            int i;

            for (i = 0; !slay_cache[i].flags.is_empty(); i++)
                if (index.is_equal(slay_cache[i].flags)) break;

            return slay_cache[i].value;
        }