Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old October 24, 2010, 23:53   #1
Kyle
Rookie
 
Kyle's Avatar
 
Join Date: Jul 2009
Posts: 15
Kyle is on a distinguished road
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];    <-----  crash occured on this line
}

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 25, 2010 at 00:34.
Kyle is offline   Reply With Quote
Old October 25, 2010, 01:48   #2
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 54
Posts: 7,849
Donated: $60
Nick will become famous soon enough
Quote:
Originally Posted by Kyle View Post
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.
Nick is offline   Reply With Quote
Old October 25, 2010, 03:47   #3
Kyle
Rookie
 
Kyle's Avatar
 
Join Date: Jul 2009
Posts: 15
Kyle is on a distinguished road
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
Kyle is offline   Reply With Quote
Old October 26, 2010, 07:30   #4
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,391
Donated: $40
Pete Mack is on a distinguished road
You might want to take a look at NPP, where there are already 10 stores [0-9]
(Basic 8 + library + quest shop)
Pete Mack is offline   Reply With Quote
Old October 27, 2010, 17:02   #5
Kyle
Rookie
 
Kyle's Avatar
 
Join Date: Jul 2009
Posts: 15
Kyle is on a distinguished road
Will do, thanks!
Kyle is offline   Reply With Quote
Old October 28, 2010, 18:31   #6
Kyle
Rookie
 
Kyle's Avatar
 
Join Date: Jul 2009
Posts: 15
Kyle is on a distinguished road
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?
Kyle is offline   Reply With Quote
Old October 29, 2010, 17:47   #7
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,936
Donated: $40
takkaria is on a distinguished road
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-
takkaria is offline   Reply With Quote
Old October 30, 2010, 01:52   #8
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 54
Posts: 7,849
Donated: $60
Nick will become famous soon enough
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.
Nick is offline   Reply With Quote
Old October 30, 2010, 02:18   #9
nppangband
NPPAngband Maintainer
 
Join Date: Dec 2008
Location: Stat Gain, Angband
Posts: 926
nppangband is on a distinguished road
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 is offline   Reply With Quote
Old October 30, 2010, 21:56   #10
Kyle
Rookie
 
Kyle's Avatar
 
Join Date: Jul 2009
Posts: 15
Kyle is on a distinguished road
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.
Kyle is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Fonts? (X11 version) danaris Vanilla 8 March 17, 2010 19:12
Adding Effects to Angband PaulBlay Development 0 March 28, 2009 13:08
If you were a shopkeeper; which shop would you own? Bandobras Vanilla 27 March 22, 2008 17:14
Shop observations ish Vanilla 7 August 29, 2007 01:32
Magic Shop - Rings/Amulets SocietalEclipse Vanilla 2 July 21, 2007 21:28


All times are GMT +1. The time now is 19:48.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.