The forum is being replaced with new software. Please use the replacement hosted at https://forum.angband.live/ in the meantime. These forums will stay open until migrating old topics can be achieved, though posting will eventually be locked. Thankyou for your patience.

tiny little unimportant DJA bug that's been bugging me

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • will_asher
    DaJAngband Maintainer
    • Apr 2007
    • 1063

    tiny little unimportant DJA bug that's been bugging me

    There's a very unimportant bug that's been getting on my nerves and it involves a piece of code which is gibberish to me so I'm asking for help:

    The "C" line in p_race text lists recommended classes for that race. The recommended classes show up in a brighter color in the birth menu, but this doesn't work. No recommended classes below the alchemist (class index 7) ever show up in a brighter color.

    The relevant piece of code (I think) is this little function in birth.c
    Code:
    /* CLASS */
    static void display_class(menu_type *menu, int oid, bool cursor,
    							int row, int col, int width)
    {
    	byte attr = curs_attrs[0 != (rp_ptr->choice & (1L << oid))][0 != cursor];
    	c_put_str(attr, c_name + c_info[oid].name, row, col);
    }
    I have no idea what (1L << oid) means so I can't fix the bug.

    I looked in init.c where it reads the C: line in p_race.txt and it uses a similar thing:
    Code:
    		/* Hack - Parse this entry */
    		pr_ptr->choice |= (1 << atoi(s));
    Does this put a limit on how many C: entries there can be?
    "atoi" isn't defined as a function anywhere so I assume it's an innate C thing that I haven't learned.
    Will_Asher
    aka LibraryAdventurer

    My old variant DaJAngband:
    http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)
  • d_m
    Angband Devteam member
    • Aug 2008
    • 1516

    #2
    Here's the idea:

    Code:
    1 << 1 == 2
    1 << 2 == 4
    1 << 3 == 8
    ...
    1 << 8 == 256
    the "L" means that 1 is long, so it has more bits. This is important because if you shift the bit over too far it will fall off the end (I think).

    Also, atoi is translating a string representation of a number into an int.

    Code:
    atoi("10") == 10
    atoi("3") == 3
    Hope this helps.
    linux->xterm->screen->pmacs

    Comment

    • PowerDiver
      Prophet
      • Mar 2008
      • 2782

      #3
      Originally posted by will_asher
      I looked in init.c where it reads the C: line in p_race.txt and it uses a similar thing:
      Code:
      		/* Hack - Parse this entry */
      		pr_ptr->choice |= (1 << atoi(s));
      Does this put a limit on how many C: entries there can be?
      That's the bug. For some absurd reason, there are lots of things defined as bytes or chars that should not be. That variable is only 8 bits, so if you have more than 8 choices it will not work.

      The simple change is to define choice to be a different size, say unsigned int, but that may break savefile compatibility if the value is written and reloaded from the savefile.

      Comment

      • d_m
        Angband Devteam member
        • Aug 2008
        • 1516

        #4
        Originally posted by PowerDiver
        That's the bug. For some absurd reason, there are lots of things defined as bytes or chars that should not be. That variable is only 8 bits, so if you have more than 8 choices it will not work.
        Angband does *love* bit-encodings. I guess 640k should be enough for anyone, huh?
        linux->xterm->screen->pmacs

        Comment

        • will_asher
          DaJAngband Maintainer
          • Apr 2007
          • 1063

          #5
          Thanks, it works as it should now.
          BTW, 'choice' isn't used in savefiles, but I've already broken savefiles in other ways.
          Will_Asher
          aka LibraryAdventurer

          My old variant DaJAngband:
          http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)

          Comment

          • PowerDiver
            Prophet
            • Mar 2008
            • 2782

            #6
            Originally posted by d_m
            Angband does *love* bit-encodings. I guess 640k should be enough for anyone, huh?
            It's one thing to try to save space in a structure that is used 1000 times. But to worry about space in a variable that is only used once is insane. It makes more sense to use a long than a byte if you think anyone might ever want to extend things in the future.

            Comment

            • Magnate
              Angband Devteam member
              • May 2007
              • 4916

              #7
              Originally posted by PowerDiver
              It's one thing to try to save space in a structure that is used 1000 times. But to worry about space in a variable that is only used once is insane. It makes more sense to use a long than a byte if you think anyone might ever want to extend things in the future.
              Don't forget the age of the codebase. Angband wasn't written from scratch - I'm not even sure if Moria was, but even if it was we're talking mid-eighties here. In those days you saved space in every variable, however rarely it was used.
              "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

              Comment

              • konijn_
                Hellband maintainer
                • Jul 2007
                • 345

                #8
                Originally posted by Magnate
                Don't forget the age of the codebase. Angband wasn't written from scratch - I'm not even sure if Moria was, but even if it was we're talking mid-eighties here. In those days you saved space in every variable, however rarely it was used.
                Plus, bitflags are inherently cool

                T.
                * Are you ready for something else ? Hellband 0.8.8 is out! *

                Comment

                Working...
                😀
                😂
                🥰
                😘
                🤢
                😎
                😞
                😡
                👍
                👎
                MMOMBuy POE 2 Currency