Source:NetHack 2.3e/shknam.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to shknam.c from the source code of NetHack 2.3e.

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

Screenshots and source code from Hack are used under the CWI license.

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