![]() |
#1 |
Rookie
Join Date: Jul 2009
Posts: 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 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; 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 Code:
Store 6 has too few entries (read 28, expected 29). -more- Code:
# Magic-user's S:6:29 -I:1:ring:Searching +I:2:ring:Searching I:1:ring:Feather Falling 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 24, 2010 at 23:34. |
![]() |
![]() |
![]() |
#2 |
Vanilla maintainer
Join Date: Apr 2007
Location: Canberra, Australia
Age: 58
Posts: 9,529
Donated: $60
![]() ![]() |
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. |
![]() |
![]() |
![]() |
#3 |
Rookie
Join Date: Jul 2009
Posts: 15
![]() |
st = 7 in the context of
Code:
static s16b store_get_choice(int st) 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); } so still unresolved ![]() |
![]() |
![]() |
![]() |
#4 |
Prophet
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,802
Donated: $40
![]() |
You might want to take a look at NPP, where there are already 10 stores [0-9]
(Basic 8 + library + quest shop) |
![]() |
![]() |
![]() |
#5 |
Rookie
Join Date: Jul 2009
Posts: 15
![]() |
Will do, thanks!
|
![]() |
![]() |
![]() |
#6 |
Rookie
Join Date: Jul 2009
Posts: 15
![]() |
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 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 Any more advice? |
![]() |
![]() |
![]() |
#7 |
Veteran
Join Date: Apr 2007
Posts: 1,951
Donated: $40
![]() |
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- |
![]() |
![]() |
![]() |
#8 |
Vanilla maintainer
Join Date: Apr 2007
Location: Canberra, Australia
Age: 58
Posts: 9,529
Donated: $60
![]() ![]() |
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. |
![]() |
![]() |
![]() |
#9 |
NPPAngband Maintainer
Join Date: Dec 2008
Location: Stat Gain, Angband
Posts: 926
![]() |
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. |
![]() |
![]() |
![]() |
#10 |
Rookie
Join Date: Jul 2009
Posts: 15
![]() |
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. ![]() |
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Adding Fonts? (X11 version) | danaris | Vanilla | 8 | March 17, 2010 18:12 |
Adding Effects to Angband | PaulBlay | Development | 0 | March 28, 2009 12:08 |
If you were a shopkeeper; which shop would you own? | Bandobras | Vanilla | 27 | March 22, 2008 16:14 |
Shop observations | ish | Vanilla | 7 | August 29, 2007 00:32 |
Magic Shop - Rings/Amulets | SocietalEclipse | Vanilla | 2 | July 21, 2007 20:28 |