Beispiel #1
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);
        }
Beispiel #2
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;
        }