Adding a new shop to Angband 3.1.1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kyle
    Rookie
    • Jul 2009
    • 15

    Adding a new shop to Angband 3.1.1

    hey all, I'm just playing around at this stage and trying to familiarize myself with the code

    one thing I figured I'd try to do first is add a new shop

    These are the steps I took:

    In defines.h

    Code:
    /*
     * Total number of stores (see "store.c", etc)
     */
    - #define MAX_STORES	   8
    + #define MAX_STORES	   9
    
    
      /*
       * Store index definitions (see "store.c", etc)
       */
      #define STORE_GENERAL	        0
      #define STORE_ARMOR		1
      #define STORE_WEAPON	        2
      #define STORE_TEMPLE          3
      #define STORE_ALCHEMY	        4
      #define STORE_MAGIC		5
      #define STORE_B_MARKET	6
    - #define STORE_HOME		8
    + #define STORE_KYLE            7
    + #define STORE_HOME		8
    Then in init1.c

    Code:
    	}
    			}
    
    
    			if (2 != sscanf(buf, "S:%d:%d", &num, &slots))
    				return PARSE_ERROR_GENERIC;
    -			if (num < 2 || num > 6)
    +			if (num < 2 || num > 7)
    				return PARSE_ERROR_GENERIC;
    
    			error_idx = num;
    Then in edit/store.txt
    Code:
     # Magic-user's
     S:6:29
     I:1:ring:Searching
     I:1:ring:Feather Falling
     I:1:ring:Protection
     I:1:amulet:Charisma
     I:1:amulet:Slow Digestion
     I:1:amulet:Resist Acid
     #I:1:rod:Trap Location
     #I:1:rod:Door/Stair Location 
     #I:2:rod:Treasure Location
     I:1:wand:Slow Monster
     I:1:wand:Confuse Monster
     I:1:wand:Sleep Monster
     I:1:wand:Magic Missile
     I:1:wand:Stinking Cloud
     I:1:wand:Wonder
     I:2:staff:Teleportation
     I:2:staff:Identify
     I:1:staff:Light
     I:1:staff:Mapping
     I:1:staff:Detect Invisible
     I:1:staff:Detect Evil
     I:3:magic book:[Magic for Beginners]
     I:2:magic book:[Conjurings and Tricks]
     I:2:magic book:[Incantations and Illusions]
     I:1:magic book:[Sorcery and Evocations]
    +
    +# Kyle's
    +S:7:1
    +I:1:ring:Searching
    Then when I compiled and booted, I got an error message during the boot process.

    Code:
    Store 6 has too few entries (read 28, expected 29). -more-
    This struck me as odd, since Store 6 was one of the stock stores which I didn't touch. So sure enough I counted and noticed that there were only 28 items listed in the shop. So to deal with this quickly, I made the following change:

    Code:
     # Magic-user's
     S:6:29
    -I:1:ring:Searching
    +I:2:ring:Searching
     I:1:ring:Feather Falling
    So then the program booted, and I made a new character, then when I was finished rolling my character and naming it. I had a crash

    Code:
    static s16b store_get_choice(int st)
    {
    	int r;
    	store_type *st_ptr = &store[st];
    
    	/* Choose a random entry from the store's table */
    	r = randint0(st_ptr->table_num);
    
    	/* Return it */
    	return st_ptr->table[r];    [b]<-----  crash occured on this line[/b]
    }

    From my debugger, I see that st_ptr->table is NULL. So that makes it obvious why the crash is happening.

    I'm guessing that this value was initialized to NULL somewhere but wasn't set to a meaningful value along with the other stores like it needs to be.

    I'm new to the code, so I was hoping someone could help me discover the solution?

    Thanks!

    Note: I realize that the store will not appear in town with just these changes.
    Last edited by Kyle; October 24, 2010, 23:34.
  • Nick
    Vanilla maintainer
    • Apr 2007
    • 9344

    #2
    Originally posted by Kyle
    I'm new to the code, so I was hoping someone could help me discover the solution?
    I can't see an obvious answer - it seems that st_ptr->table should be set in init1.c. My first look would be at which store the crash occurs in.
    One for the Dark Lord on his dark throne
    In the Land of Mordor where the Shadows lie.

    Comment

    • Kyle
      Rookie
      • Jul 2009
      • 15

      #3
      st = 7 in the context of
      Code:
      static s16b store_get_choice(int st)
      when the program crashes

      so it's definitely crashing on the final store (the one I added)

      and yes it does seem like str_ptr->table should be set properly
      Code:
      			if (num < 2 || num > 7)
      				return PARSE_ERROR_GENERIC;
      
      			error_idx = num;
      
      			/* Account for 0-based indexing */
      			num--;
      			store_num = num;
      
      			/* Set up this store */
      			st_ptr = &store[num];
      			st_ptr->table_size = slots;
      			st_ptr->table = C_ZNEW(st_ptr->table_size, s16b);
      		}
      On the last line, it gets set. And I made sure that this code wasnt being skipped or anything by putting a msg_format("test"); statement to make sure


      so still unresolved

      Comment

      • Pete Mack
        Prophet
        • Apr 2007
        • 6697

        #4
        You might want to take a look at NPP, where there are already 10 stores [0-9]
        (Basic 8 + library + quest shop)

        Comment

        • Kyle
          Rookie
          • Jul 2009
          • 15

          #5
          Will do, thanks!

          Comment

          • Kyle
            Rookie
            • Jul 2009
            • 15

            #6
            Unfortunately the shop system in NPAngband has been completely restructured. So that system is not helpful for my purposes.


            Also I realized that I needed to add to "shop_own.txt"
            Any other advice?

            I changed:

            Code:
            # Alchemist
            N:4
            S:10000:Mauser the Chemist (Half-Elf)
            S:10000:Wizzle the Chaotic (Hobbit)
            S:15000:Ga-nat the Greedy (Gnome)
            S:15000:Vella the Slender (Human)
            
            # Magic Shop
            N:5
            S:15000:Ariel the Sorceress (Half-Elf)
            S:20000:Buggerby the Great (Gnome)
            S:25000:Inglorian the Mage (Human)
            S:30000:Luthien Starshine (High-Elf)
            
            # Black Market
            N:6
            S:15000:Lo-Hak the Awful (Half-Troll)
            S:20000:Histor the Goblin (Kobold)
            S:25000:Durwin the Shifty (Half-Orc)
            S:30000:Drago the Fair (Elf)
            
            # Home
            N:7
            S:0:Your home
            S:0:Your home
            S:0:Your home
            S:0:Your home
            to

            Code:
            # Alchemist
            N:4
            S:10000:Mauser the Chemist (Half-Elf)
            S:10000:Wizzle the Chaotic (Hobbit)
            S:15000:Ga-nat the Greedy (Gnome)
            S:15000:Vella the Slender (Human)
            
            # Magic Shop
            N:5
            S:15000:Ariel the Sorceress (Half-Elf)
            S:20000:Buggerby the Great (Gnome)
            S:25000:Inglorian the Mage (Human)
            S:30000:Luthien Starshine (High-Elf)
            
            # Kyle's store
            N:6
            S:15000:Lo-Hak the Awful (Half-Troll)
            S:20000:Histor the Goblin (Kobold)
            S:25000:Durwin the Shifty (Half-Orc)
            S:30000:Drago the Fair (Elf)
            
            # Black Market
            N:7
            S:15000:Lo-Hak the Awful (Half-Troll)
            S:20000:Histor the Goblin (Kobold)
            S:25000:Durwin the Shifty (Half-Orc)
            S:30000:Drago the Fair (Elf)
            
            # Home
            N:8
            S:0:Your home
            S:0:Your home
            S:0:Your home
            S:0:Your home
            Now I hit an endless loop at run time (after character birth). So I get no crash, which means no debugging info.

            Any more advice?

            Comment

            • takkaria
              Veteran
              • Apr 2007
              • 1895

              #7
              I can't help you out, I'm afraid. There are a lot of hardcoded assumptions with it comes to stores and even I get confused by them sometime.
              takkaria whispers something about options. -more-

              Comment

              • Nick
                Vanilla maintainer
                • Apr 2007
                • 9344

                #8
                Could I recommend making your code public? In particular, the angband repository at github is a flurry of activity at the moment. Setting yourself up with an identity on github, making your own fork, and then making the changes to that is fairly easy (this thread has some useful info), and has the advantage that anyone can look at the code directly rather than having to ask for details.
                One for the Dark Lord on his dark throne
                In the Land of Mordor where the Shadows lie.

                Comment

                • nppangband
                  NPPAngband Maintainer
                  • Dec 2008
                  • 901

                  #9
                  I see the problem. Notice in defines.h you have Kyles store as 7, and the black market defined as 6. Then in shop_own you have that reversed. There is specific object generation code for the black market that is now accidentally preventing objects from being generated for your special store and causing the crash.

                  Unless Vanilla has changed, you will also have to do some editing in terrain.txt to sucessfully create the store. There is alot of code that assumes the stores are set in a certain order in terrain.txt, and within a specified range. There are many feature names and ranges of names that are hard-coded throughout the source that you will have to change.

                  Oh, and also you will have to change town_gen in generate.c to get the store to appear when the town is drawn.
                  NPPAngband current home page: http://nppangband.bitshepherd.net/
                  Source code repository:
                  https://github.com/nppangband/NPPAngband_QT
                  Downloads:
                  https://app.box.com/s/1x7k65ghsmc31usmj329pb8415n1ux57

                  Comment

                  • Kyle
                    Rookie
                    • Jul 2009
                    • 15

                    #10
                    Thanks very much. I'm not at home right now to test it but I will try it when I get back.

                    Also, I will follow the advice about publicizing the code. I'm sure it will make it easier to help me, thus getting me more help.

                    Comment

                    Working...
                    😀
                    😂
                    🥰
                    😘
                    🤢
                    😎
                    😞
                    😡
                    👍
                    👎