Wikihack
Advertisement

Below is the full text to shknam.c from the source code of NetHack 2.2a. To link to a particular line, write [[NetHack 2.2a/shknam.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

Screenshots and source code from Hack are used under the CWI license.
1.    /*	SCCS Id: @(#)shknam.c	2.1	87/09/23
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    
4.    /* shknam.c -- initialize a shop */
5.    
6.    #include "hack.h"
7.    #include "mkroom.h"
8.    #include "eshk.h"
9.    
10.   extern struct monst *makemon();
11.   
12.   static char *shkliquors[] = {
13.       /* Ukraine */
14.       "Njezjin", "Tsjernigof", "Gomel", "Ossipewsk", "Gorlowka",
15.       /* N. Russia */
16.       "Konosja", "Weliki Oestjoeg", "Syktywkar", "Sablja",
17.       "Narodnaja", "Kyzyl",
18.       /* Silezie */
19.       "Walbrzych", "Swidnica", "Klodzko", "Raciborz", "Gliwice",
20.       "Brzeg", "Krnov", "Hradec Kralove",
21.       /* Schweiz */
22.       "Leuk", "Brig", "Brienz", "Thun", "Sarnen", "Burglen", "Elm",
23.       "Flims", "Vals", "Schuls", "Zum Loch",
24.       ""
25.   };
26.   
27.   static char *shkbooks[] = {
28.       /* Eire */
29.       "Skibbereen", "Kanturk", "Rath Luirc", "Ennistymon", "Lahinch",
30.       "Kinnegad", "Lugnaquillia", "Enniscorthy", "Gweebarra",
31.       "Kittamagh", "Nenagh", "Sneem", "Ballingeary", "Kilgarvan",
32.       "Cahersiveen", "Glenbeigh", "Kilmihil", "Kiltamagh",
33.       "Droichead Atha", "Inniscrone", "Clonegal", "Lisnaskea",
34.       "Culdaff", "Dunfanaghy", "Inishbofin", "Kesh",
35.       ""
36.   };
37.   
38.   static char *shkarmors[] = {
39.       /* Turquie */
40.       "Demirci", "Kalecik", "Boyabai", "Yildizeli", "Gaziantep",
41.       "Siirt", "Akhalataki", "Tirebolu", "Aksaray", "Ermenak",
42.       "Iskenderun", "Kadirli", "Siverek", "Pervari", "Malasgirt",
43.       "Bayburt", "Ayancik", "Zonguldak", "Balya", "Tefenni",
44.       "Artvin", "Kars", "Makharadze", "Malazgirt", "Midyat",
45.       "Birecik", "Kirikkale", "Alaca", "Polatli", "Nallihan",
46.       ""
47.   };
48.   
49.   static char *shkwands[] = {
50.       /* Wales */
51.       "Yr Wyddgrug", "Trallwng", "Mallwyd", "Pontarfynach",
52.       "Rhaeader", "Llandrindod", "Llanfair-ym-muallt",
53.       "Y-Fenni", "Measteg", "Rhydaman", "Beddgelert",
54.       "Curig", "Llanrwst", "Llanerchymedd", "Caergybi",
55.       /* Scotland */
56.       "Nairn", "Turriff", "Inverurie", "Braemar", "Lochnagar",
57.       "Kerloch", "Beinn a Ghlo", "Drumnadrochit", "Morven",
58.       "Uist", "Storr", "Sgurr na Ciche", "Cannich", "Gairloch",
59.       "Kyleakin", "Dunvegan",
60.       ""
61.   };
62.   
63.   static char *shkrings[] = {
64.       /* Hollandse familienamen */
65.       "Feyfer", "Flugi", "Gheel", "Havic", "Haynin", "Hoboken",
66.       "Imbyze", "Juyn", "Kinsky", "Massis", "Matray", "Moy",
67.       "Olycan", "Sadelin", "Svaving", "Tapper", "Terwen", "Wirix",
68.       "Ypey",
69.       /* Skandinaviske navne */
70.       "Rastegaisa", "Varjag Njarga", "Kautekeino", "Abisko",
71.       "Enontekis", "Rovaniemi", "Avasaksa", "Haparanda",
72.       "Lulea", "Gellivare", "Oeloe", "Kajaani", "Fauske",
73.       ""
74.   };
75.   
76.   static char *shkfoods[] = {
77.       /* Indonesia */
78.       "Djasinga", "Tjibarusa", "Tjiwidej", "Pengalengan",
79.       "Bandjar", "Parbalingga", "Bojolali", "Sarangan",
80.       "Ngebel", "Djombang", "Ardjawinangun", "Berbek",
81.       "Papar", "Baliga", "Tjisolok", "Siboga", "Banjoewangi",
82.       "Trenggalek", "Karangkobar", "Njalindoeng", "Pasawahan",
83.       "Pameunpeuk", "Patjitan", "Kediri", "Pemboeang", "Tringanoe",
84.       "Makin", "Tipor", "Semai", "Berhala", "Tegal", "Samoe",
85.       ""
86.   };
87.   
88.   static char *shkweapons[] = {
89.       /* Perigord */
90.       "Voulgezac", "Rouffiac", "Lerignac", "Touverac", "Guizengeard",
91.       "Melac", "Neuvicq", "Vanzac", "Picq", "Urignac", "Corignac",
92.       "Fleac", "Lonzac", "Vergt", "Queyssac", "Liorac", "Echourgnac",
93.       "Cazelon", "Eypau", "Carignan", "Monbazillac", "Jonzac",
94.       "Pons", "Jumilhac", "Fenouilledes", "Laguiolet", "Saujon",
95.       "Eymoutiers", "Eygurande", "Eauze", "Labouheyre",
96.       ""
97.   };
98.   
99.   static char *shkgeneral[] = {
100.      /* Suriname */
101.      "Hebiwerie", "Possogroenoe", "Asidonhopo", "Manlobbi",
102.      "Adjama", "Pakka Pakka", "Kabalebo", "Wonotobo",
103.      "Akalapi", "Sipaliwini",
104.      /* Greenland */
105.      "Annootok", "Upernavik", "Angmagssalik",
106.      /* N. Canada */
107.      "Aklavik", "Inuvik", "Tuktoyaktuk",
108.      "Chicoutimi", "Ouiatchouane", "Chibougamau",
109.      "Matagami", "Kipawa", "Kinojevis",
110.      "Abitibi", "Maganasipi",
111.      /* Iceland */
112.      "Akureyri", "Kopasker", "Budereyri", "Akranes", "Bordeyri",
113.      "Holmavik",
114.      ""
115.  };
116.  
117.  /*
118.   * To add new shop types, all that is necessary is to edit the shtypes[] array.
119.   * See mkroom.h for the structure definition. Typically, you'll have to lower
120.   * some or all of the probability fields in old entries to free up some
121.   * percentage for the new type.
122.   *
123.   * The placement type field is not yet used but will be in the near future.
124.   *
125.   * The iprobs array in each entry defines the probabilities for various kinds
126.   * of artifacts to be present in the given shop type. You can associate with
127.   * each percentage either a generic artifact type (represented by one of the
128.   * *_SYM macros) or a specific artifact (represented by an onames.h define).
129.   * In the latter case, prepend it with a unary minus so the code can know
130.   * (by testing the sign) whether to use mkobj() or mksobj().
131.   */
132.  struct shclass shtypes[] = {
133.  	{"general store", RANDOM_SYM,
134.  #ifdef SPELLS
135.  	    47,
136.  #else
137.  	    50,
138.  #endif
139.  	    D_SHOP, {{100, RANDOM_SYM}, {0, 0}, {0, 0}}, shkgeneral},
140.  	{"used armor dealership", ARMOR_SYM, 14,
141.  	    D_SHOP, {{90, ARMOR_SYM}, {10, WEAPON_SYM}, {0, 0}}, shkarmors},
142.  	{"second hand bookstore", SCROLL_SYM, 10, D_SHOP,
143.  #ifdef SPELLS
144.  	    {{90, SCROLL_SYM}, {10, SPBOOK_SYM}, {0, 0}},
145.  #else
146.  	    {{100, SCROLL_SYM}, {0, 0}, {0, 0}},
147.  #endif
148.  	    shkbooks},
149.  	{"liquor emporium", POTION_SYM, 10, D_SHOP,
150.  	    {{100, POTION_SYM}, {0, 0}, {0, 0}}, shkliquors},
151.  	{"antique weapons outlet", WEAPON_SYM, 5, D_SHOP,
152.  	    {{90, WEAPON_SYM}, {10, ARMOR_SYM}, {0, 0}}, shkweapons},
153.  	{"delicatessen", FOOD_SYM, 5, D_SHOP,
154.  	    {{95, FOOD_SYM}, {5, POTION_SYM}, {0, 0}}, shkfoods},
155.  	{"jewelers", RING_SYM, 3, D_SHOP,
156.  	    {{90, RING_SYM}, {10, GEM_SYM}, {0, 0}}, shkrings},
157.  	{"quality apparel and accessories", WAND_SYM, 3, D_SHOP,
158.  	    {{90, WAND_SYM}, {5, -PAIR_OF_GLOVES}, {5, -ELVEN_CLOAK}},
159.  	     shkwands},
160.  #ifdef SPELLS
161.  	{"rare books", SPBOOK_SYM, 3, D_SHOP,
162.  	    {{90, SPBOOK_SYM}, {10, SCROLL_SYM}, {0, 0}}, shkbooks},
163.  #endif
164.  	{(char *)0, 0, 0, 0, {{0, 0}, {0, 0}, {0, 0}}, (char **)0}
165.  };
166.  
167.  static void
168.  mkshobj_at(shp, sx, sy)
169.  /* make an object of the appropriate type for a shop square */
170.  struct shclass *shp;
171.  int sx, sy;
172.  {
173.      register int	i, j;
174.      register struct monst *mtmp;
175.      int		atype;
176.  
177.      /* select an appropriate artifact type at random */
178.      for(j = rn2(100), i = 0; j -= shp->iprobs[i].iprob; i++)
179.  	if (j < 0)
180.  	    break;
181.  
182.      /* generate the appropriate object */
183.      if ((atype = shp->iprobs[i].itype) >= 0)	/* if a class was given */
184.      {
185.  	/* the artifact may actually be a mimic */
186.  	if(rn2(100) < dlevel && !m_at(sx,sy) && (mtmp=makemon(PM_MIMIC,sx,sy)))
187.  	{
188.  	    mtmp->mimic = 1;
189.  	    mtmp->mappearance =	(atype && rn2(10) < dlevel) ? atype : ']';
190.  	    return;
191.  	}
192.  
193.  	/* it's not, go ahead and generate an article of the class */
194.  	(void) mkobj_at(atype, sx, sy);
195.      }
196.      else	/* particular object was to be generated */
197.  	(void) mksobj_at(-atype, sx, sy);
198.  }
199.  
200.  void
201.  findname(nampt, nlp)
202.  /* extract a shopkeeper name for the given shop type */
203.  char *nampt;
204.  char *nlp[];
205.  {
206.      register int i;
207.  
208.      for(i = 0; i < dlevel; i++)
209.  	if (strlen(nlp[i]) == 0)
210.  	{
211.  	    /* Not enough names, try general name */
212.  	    if (nlp != shkgeneral)
213.  		findname(nampt, shkgeneral);
214.  	    else
215.  		(void) strcpy(nampt, "Dirk");
216.  	    return;
217.  	}
218.      (void) strncpy(nampt, nlp[i], PL_NSIZ);
219.      nampt[PL_NSIZ-1] = 0;
220.  }
221.  
222.  static int
223.  shkinit(shp, sroom)
224.  /* create a new shopkeeper in the given room */
225.  struct shclass	*shp;
226.  struct mkroom	*sroom;
227.  {
228.      register int sh, sx, sy;
229.      struct monst *shk;
230.  
231.      /* place the shopkeeper in the given room */
232.      sh = sroom->fdoor;
233.      sx = doors[sh].x;
234.      sy = doors[sh].y;
235.  
236.      /* check that the shopkeeper placement is sane */
237.      if(sx == sroom->lx-1) sx++; else
238.  	if(sx == sroom->hx+1) sx--; else
239.  	    if(sy == sroom->ly-1) sy++; else
240.  		if(sy == sroom->hy+1) sy--; else {
241.  #ifdef WIZARD
242.  		    /* Said to happen sometimes, but I've never seen it. */
243.  		    if(wizard) {
244.  			register int j = sroom->doorct;
245.  			extern int doorindex;
246.  
247.  			pline("Where is shopdoor?");
248.  			pline("Room at (%d,%d),(%d,%d).", sroom->lx, sroom->ly,
249.  			      sroom->hx, sroom->hy);
250.  			pline("doormax=%d doorct=%d fdoor=%d",
251.  			doorindex, sroom->doorct, sh);
252.  			while(j--) {
253.  			    pline("door [%d,%d]", doors[sh].x, doors[sh].y);
254.  			    sh++;
255.  			}
256.  			more();
257.  		    }
258.  #endif
259.  		    return(-1);
260.  		}
261.  
262.      /* now initialize the shopkeeper's monster structure */
263.  #define	ESHK	((struct eshk *)(&(shk->mextra[0])))
264.      if(!(shk = makemon(PM_SHK,sx,sy)))
265.  	return(-1);
266.      shk->isshk = shk->mpeaceful = 1;
267.      shk->msleep = 0;
268.      shk->mtrapseen = ~0;	/* we know all the traps already */
269.      ESHK->shoproom = sroom - rooms;
270.      ESHK->shoplevel = dlevel;
271.      ESHK->shd = doors[sh];
272.      ESHK->shk.x = sx;
273.      ESHK->shk.y = sy;
274.      ESHK->robbed = 0;
275.      ESHK->visitct = 0;
276.      ESHK->following = 0;
277.      shk->mgold = 1000 + 30*rnd(100);	/* initial capital */
278.      ESHK->billct = 0;
279.      findname(ESHK->shknam, shp->shknms);
280.  
281.      return(sh);
282.  }
283.  
284.  void
285.  stock_room(shp, sroom)
286.  /* stock a newly-created room with artifacts */
287.  struct shclass	*shp;
288.  register struct mkroom *sroom;
289.  {
290.      /*
291.       * Someday soon we'll dispatch on the dist field of shclass to do
292.       * different placements in this routine. Currently it only supports
293.       * shop-style placement (all squares except a row nearest the first
294.       * door get artifacts).
295.       */
296.      register int sx, sy, sh;
297.  
298.      /* first, try to place a shopkeeper in the room */
299.      if ((sh = shkinit(shp, sroom)) < 0)
300.  	return;
301.  
302.      for(sx = sroom->lx; sx <= sroom->hx; sx++)
303.  	for(sy = sroom->ly; sy <= sroom->hy; sy++){
304.  	    if((sx == sroom->lx && doors[sh].x == sx-1) ||
305.  	       (sx == sroom->hx && doors[sh].x == sx+1) ||
306.  	       (sy == sroom->ly && doors[sh].y == sy-1) ||
307.  	       (sy == sroom->hy && doors[sh].y == sy+1)) continue;
308.  	    mkshobj_at(shp, sx, sy);
309.  	}
310.  
311.      /*
312.       * Special monster placements (if any) should go here: that way,
313.       * monsters will sit on top of artifacts and not the other way around.
314.       */
315.  }
316.  
317.  saleable(nshop, obj)			/* does "shop" stock this item type */
318.  	register int	nshop;
319.  	register struct	obj *obj;
320.  {
321.  	int i;
322.  
323.  	if(shtypes[nshop].symb == RANDOM_SYM) return(1);
324.  	else {
325.  	    for(i = 0; shtypes[nshop].iprobs[i].iprob; i++)
326.  		if(shtypes[nshop].iprobs[i].itype == obj->olet) return(1);
327.  	}
328.  	return(0);
329.  }
Advertisement