Example #1
0
        /* Parsing functions for flavor.txt */
        public static Parser.Error parse_flavor_n(Parser p)
        {
            Flavor h = p.priv as Flavor;
            Flavor f = new Flavor();

            f.next = h;
            f.fidx = p.getuint("index");
            f.tval = (byte)TVal.find_idx(p.getsym("tval"));
            /* Misc.assert(f.tval); */
            if (p.hasval("sval"))
                f.sval = (byte)SVal.lookup_sval(f.tval, p.getsym("sval"));
            else
                f.sval = SVal.SV_UNKNOWN;
            p.priv = f;
            return Parser.Error.NONE;
        }
Example #2
0
        static void flavor_assign_random(byte tval)
        {
            int flavor_count = 0;
            int choice;

            /* Count the random flavors for the given tval */
            for (Flavor f = Misc.flavors; f != null; f = f.next)
            {
                if (f.tval == tval && f.sval == SVal.SV_UNKNOWN)
                {
                    flavor_count++;
                }
            }

            for (int i = 0; i < Misc.z_info.k_max; i++)
            {
                if (Misc.k_info[i] == null)
                {
                    continue;
                }
                if (Misc.k_info[i].tval != tval || Misc.k_info[i].flavor != null)
                {
                    continue;
                }

                /* HACK - Ordinary food is "boring" */
                if ((tval == TVal.TV_FOOD) && (Misc.k_info[i].sval < SVal.SV_FOOD_MIN_SHROOM))
                {
                    continue;
                }

                if (flavor_count == 0)
                {
                    Utilities.quit("Not enough flavors for tval " + tval + ".");
                }

                choice = Random.randint0(flavor_count);

                for (Flavor f = Misc.flavors; f != null; f = f.next)
                {
                    if (f.tval != tval || f.sval != SVal.SV_UNKNOWN)
                    {
                        continue;
                    }

                    if (choice == 0)
                    {
                        Misc.k_info[i].flavor = f;
                        f.sval = Misc.k_info[i].sval;
                        if (tval == TVal.TV_SCROLL)
                        {
                            f.text = scroll_adj[Misc.k_info[i].sval];
                        }
                        flavor_count--;
                        break;
                    }

                    choice--;
                }
            }
        }