Source:NetHack 3.0.0/shknam.c

From NetHackWiki
Revision as of 05:28, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 3.0.0/shknam.c moved to Source:NetHack 3.0.0/shknam.c: Robot: moved page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

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

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

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