home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / src / shknam.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  15.6 KB  |  359 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)shknam.c    3.1    93/05/15    */
  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. #ifdef OVLB
  11.  
  12. static void FDECL(mkshobj_at, (const struct shclass *,int,int));
  13. static void FDECL(nameshk, (struct monst *,const char **));
  14. static int  FDECL(shkinit, (const struct shclass *,struct mkroom *));
  15.  
  16. static const char *shkliquors[] = {
  17.     /* Ukraine */
  18.     "Njezjin", "Tsjernigof", "Gomel", "Ossipewsk", "Gorlowka",
  19.     /* N. Russia */
  20.     "Konosja", "Weliki Oestjoeg", "Syktywkar", "Sablja",
  21.     "Narodnaja", "Kyzyl",
  22.     /* Silezie */
  23.     "Walbrzych", "Swidnica", "Klodzko", "Raciborz", "Gliwice",
  24.     "Brzeg", "Krnov", "Hradec Kralove",
  25.     /* Schweiz */
  26.     "Leuk", "Brig", "Brienz", "Thun", "Sarnen", "Burglen", "Elm",
  27.     "Flims", "Vals", "Schuls", "Zum Loch",
  28.     ""
  29. };
  30.  
  31. static const char *shkbooks[] = {
  32.     /* Eire */
  33.     "Skibbereen", "Kanturk", "Rath Luirc", "Ennistymon", "Lahinch",
  34.     "Kinnegad", "Lugnaquillia", "Enniscorthy", "Gweebarra",
  35.     "Kittamagh", "Nenagh", "Sneem", "Ballingeary", "Kilgarvan",
  36.     "Cahersiveen", "Glenbeigh", "Kilmihil", "Kiltamagh",
  37.     "Droichead Atha", "Inniscrone", "Clonegal", "Lisnaskea",
  38.     "Culdaff", "Dunfanaghy", "Inishbofin", "Kesh",
  39.     ""
  40. };
  41.  
  42. static const char *shkarmors[] = {
  43.     /* Turquie */
  44.     "Demirci", "Kalecik", "Boyabai", "Yildizeli", "Gaziantep",
  45.     "Siirt", "Akhalataki", "Tirebolu", "Aksaray", "Ermenak",
  46.     "Iskenderun", "Kadirli", "Siverek", "Pervari", "Malasgirt",
  47.     "Bayburt", "Ayancik", "Zonguldak", "Balya", "Tefenni",
  48.     "Artvin", "Kars", "Makharadze", "Malazgirt", "Midyat",
  49.     "Birecik", "Kirikkale", "Alaca", "Polatli", "Nallihan",
  50.     ""
  51. };
  52.  
  53. static const char *shkwands[] = {
  54.     /* Wales */
  55.     "Yr Wyddgrug", "Trallwng", "Mallwyd", "Pontarfynach",
  56.     "Rhaeader", "Llandrindod", "Llanfair-ym-muallt",
  57.     "Y-Fenni", "Measteg", "Rhydaman", "Beddgelert",
  58.     "Curig", "Llanrwst", "Llanerchymedd", "Caergybi",
  59.     /* Scotland */
  60.     "Nairn", "Turriff", "Inverurie", "Braemar", "Lochnagar",
  61.     "Kerloch", "Beinn a Ghlo", "Drumnadrochit", "Morven",
  62.     "Uist", "Storr", "Sgurr na Ciche", "Cannich", "Gairloch",
  63.     "Kyleakin", "Dunvegan",
  64.     ""
  65. };
  66.  
  67. static const char *shkrings[] = {
  68.     /* Hollandse familienamen */
  69.     "Feyfer", "Flugi", "Gheel", "Havic", "Haynin", "Hoboken",
  70.     "Imbyze", "Juyn", "Kinsky", "Massis", "Matray", "Moy",
  71.     "Olycan", "Sadelin", "Svaving", "Tapper", "Terwen", "Wirix",
  72.     "Ypey",
  73.     /* Skandinaviske navne */
  74.     "Rastegaisa", "Varjag Njarga", "Kautekeino", "Abisko",
  75.     "Enontekis", "Rovaniemi", "Avasaksa", "Haparanda",
  76.     "Lulea", "Gellivare", "Oeloe", "Kajaani", "Fauske",
  77.     ""
  78. };
  79.  
  80. static const char *shkfoods[] = {
  81.     /* Indonesia */
  82.     "Djasinga", "Tjibarusa", "Tjiwidej", "Pengalengan",
  83.     "Bandjar", "Parbalingga", "Bojolali", "Sarangan",
  84.     "Ngebel", "Djombang", "Ardjawinangun", "Berbek",
  85.     "Papar", "Baliga", "Tjisolok", "Siboga", "Banjoewangi",
  86.     "Trenggalek", "Karangkobar", "Njalindoeng", "Pasawahan",
  87.     "Pameunpeuk", "Patjitan", "Kediri", "Pemboeang", "Tringanoe",
  88.     "Makin", "Tipor", "Semai", "Berhala", "Tegal", "Samoe",
  89.     ""
  90. };
  91.  
  92. static const char *shkweapons[] = {
  93.     /* Perigord */
  94.     "Voulgezac", "Rouffiac", "Lerignac", "Touverac", "Guizengeard",
  95.     "Melac", "Neuvicq", "Vanzac", "Picq", "Urignac", "Corignac",
  96.     "Fleac", "Lonzac", "Vergt", "Queyssac", "Liorac", "Echourgnac",
  97.     "Cazelon", "Eypau", "Carignan", "Monbazillac", "Jonzac",
  98.     "Pons", "Jumilhac", "Fenouilledes", "Laguiolet", "Saujon",
  99.     "Eymoutiers", "Eygurande", "Eauze", "Labouheyre",
  100.     ""
  101. };
  102.  
  103. static const char *shktools[] = {
  104.     /* Spmi */
  105.     "Ymla", "Eed-morra", "Cubask", "Nieb", "Bnowr Falr", "Telloc Cyaj",
  106.     "Sperc", "Noskcirdneh", "Yawolloh", "Hyeghu", "Niskal", "Trahnil",
  107.     "Htargcm", "Enrobwem", "Kachzi Rellim", "Regien", "Donmyar",
  108.     "Yelpur", "Nosnehpets", "Stewe", "Renrut", "_Zlaw", "Nosalnef",
  109.     "Rewuorb", "Rellenk", "Yad", "Cire Htims", "Y-crad", "Nenilukah",
  110.     "Corsh", "Aned",
  111. #ifdef OVERLAY
  112.     "Erreip", "Nehpets", "Mron", "Snivek", "Lapu",
  113. #endif
  114. #ifdef WIN32
  115.     "Lechaim",
  116. #endif
  117. #ifdef MAC
  118.     "Nhoj-lee", "Evad\'kh", "Ettaw-noj", "Tsew-mot", "Ydna-s",
  119.     "Yao-hang", "Tonbar",
  120. #endif
  121. #ifdef AMIGA
  122.     "Falo", "Nosid-da\'r", "Ekim-p", "Rebrol-nek", "Noslo", "Yl-rednow",
  123.     "Mured-oog",
  124. #endif
  125. #ifdef VMS
  126.     "Lez-tneg", "Ytnu-haled", "Niknar",
  127. #endif
  128.     ""
  129. };
  130.  
  131. static const char *shklight[] = {
  132.     /* Romania */
  133.     "Zarnesti", "Slanic", "Nehoiasu", "Ludus", "Sighisoara", "Nisipitu",
  134.     "Razboieni", "Bicaz", "Dorohoi", "Vaslui", "Fetesti", "Tirgu Neamt",
  135.     "Babadag", "Zimnicea", "Zlatna", "Jiu", "Eforie", "Mamaia",
  136.     /* Bulgaria */
  137.     "Silistra", "Tulovo", "Panagyuritshte", "Smolyan", "Kirklareli",
  138.     "Pernik", "Lom", "Haskovo", "Dobrinishte", "Varvara", "Oryahovo",
  139.     "Troyan", "Lovech", "Sliven",
  140.     ""
  141. };
  142.  
  143. static const char *shkgeneral[] = {
  144.     /* Suriname */
  145.     "Hebiwerie", "Possogroenoe", "Asidonhopo", "Manlobbi",
  146.     "Adjama", "Pakka Pakka", "Kabalebo", "Wonotobo",
  147.     "Akalapi", "Sipaliwini",
  148.     /* Greenland */
  149.     "Annootok", "Upernavik", "Angmagssalik",
  150.     /* N. Canada */
  151.     "Aklavik", "Inuvik", "Tuktoyaktuk",
  152.     "Chicoutimi", "Ouiatchouane", "Chibougamau",
  153.     "Matagami", "Kipawa", "Kinojevis",
  154.     "Abitibi", "Maganasipi",
  155.     /* Iceland */
  156.     "Akureyri", "Kopasker", "Budereyri", "Akranes", "Bordeyri",
  157.     "Holmavik",
  158.     ""
  159. };
  160.  
  161. /*
  162.  * To add new shop types, all that is necessary is to edit the shtypes[] array.
  163.  * See mkroom.h for the structure definition.  Typically, you'll have to lower
  164.  * some or all of the probability fields in old entries to free up some
  165.  * percentage for the new type.
  166.  *
  167.  * The placement type field is not yet used but will be in the near future.
  168.  *
  169.  * The iprobs array in each entry defines the probabilities for various kinds
  170.  * of objects to be present in the given shop type.  You can associate with
  171.  * each percentage either a generic object type (represented by one of the
  172.  * *_CLASS macros) or a specific object (represented by an onames.h define).
  173.  * In the latter case, prepend it with a unary minus so the code can know
  174.  * (by testing the sign) whether to use mkobj() or mksobj().
  175.  */
  176.  
  177. const struct shclass shtypes[] = {
  178.     {"general store", RANDOM_CLASS, 44,
  179.         D_SHOP, {{100, RANDOM_CLASS}, {0, 0}, {0, 0}}, shkgeneral},
  180.     {"used armor dealership", ARMOR_CLASS, 14,
  181.         D_SHOP, {{90, ARMOR_CLASS}, {10, WEAPON_CLASS}, {0, 0}},
  182.          shkarmors},
  183.     {"second-hand bookstore", SCROLL_CLASS, 10, D_SHOP,
  184.         {{90, SCROLL_CLASS}, {10, SPBOOK_CLASS}, {0, 0}}, shkbooks},
  185.     {"liquor emporium", POTION_CLASS, 10, D_SHOP,
  186.         {{100, POTION_CLASS}, {0, 0}, {0, 0}}, shkliquors},
  187.     {"antique weapons outlet", WEAPON_CLASS, 5, D_SHOP,
  188.         {{90, WEAPON_CLASS}, {10, ARMOR_CLASS}, {0, 0}}, shkweapons},
  189.     {"delicatessen", FOOD_CLASS, 5, D_SHOP,
  190.         {{95, FOOD_CLASS}, {5, POTION_CLASS}, {0, 0}}, shkfoods},
  191.     {"jewelers", RING_CLASS, 3, D_SHOP,
  192.         {{85, RING_CLASS}, {10, GEM_CLASS}, {5, AMULET_CLASS}, {0, 0}},
  193.         shkrings},
  194.     {"quality apparel and accessories", WAND_CLASS, 3, D_SHOP,
  195.         {{90, WAND_CLASS}, {5, -LEATHER_GLOVES}, {5, -ELVEN_CLOAK}, {0, 0}},
  196.          shkwands},
  197.     {"hardware store", TOOL_CLASS, 3, D_SHOP,
  198.         {{100, TOOL_CLASS}, {0, 0}, {0, 0}}, shktools},
  199.     /* Actually shktools is ignored; the code specifically chooses a
  200.      * random implementor name (along with candle shops having
  201.      * random shopkeepers)
  202.      */
  203.     {"rare books", SPBOOK_CLASS, 3, D_SHOP,
  204.         {{90, SPBOOK_CLASS}, {10, SCROLL_CLASS}, {0, 0}}, shkbooks},
  205.     /* Shops below this point are "unique".  That is they must all have a
  206.      * probability of zero.  They are only created via the special level
  207.      * loader.
  208.      */
  209.     {"lighting store", TOOL_CLASS, 0, D_SHOP,
  210.         {{32, -WAX_CANDLE}, {50, -TALLOW_CANDLE},
  211.          {5, -BRASS_LANTERN}, {10, -OIL_LAMP}, {3, -MAGIC_LAMP}}, shklight},
  212.     {NULL, 0, 0, 0, {{0, 0}, {0, 0}, {0, 0}}, 0}
  213. };
  214.  
  215. #else    /* OVLB */
  216.  
  217. extern const struct shclass shtypes[];
  218.  
  219. #endif    /* OVLB */
  220.  
  221. #ifdef OVLB
  222.  
  223. #if 0
  224. /* validate shop probabilities; otherwise incorrect local changes could
  225.    end up provoking infinite loops or wild subscripts fetching garbage */
  226. void
  227. init_shop_selection()
  228. {
  229.     register int i, j, item_prob, shop_prob;
  230.  
  231.     for (shop_prob = 0, i = 0; i < SIZE(shtypes); i++) {
  232.         shop_prob += shtypes[i].prob;
  233.         for (item_prob = 0, j = 0; j < SIZE(shtypes[0].iprobs); j++)
  234.             item_prob += shtypes[i].iprobs[j].iprob;
  235.         if (item_prob != 100)
  236.             panic("item probabilities total to %d for %s shops!",
  237.                 item_prob, shtypes[i].name);
  238.     }
  239.     if (shop_prob != 100)
  240.         panic("shop probabilities total tSHK(shk)->debit = 0L;
  241.     ESHK(shk)->loan = 0L;
  242.     ESHK(shk)->visitct = 0;
  243.     ESHK(shk)->following = 0;
  244.     ESHK(shk)->billct = 0;
  245.     shk->mgold = 1000L + 30L*(long)rnd(100);    /* initial capital */
  246.     nameshk(shk, shp->shknms);
  247.  
  248.     return(sh);
  249. }
  250.  
  251. /* stock a newly-created room with objects */
  252. void
  253. stock_room(shp_indx, sroom)
  254. int shp_indx;
  255. register struct mkroom *sroom;
  256. {
  257.     /*
  258.      * Someday soon we'll dispatch on the shdist field of shclass to do
  259.      * different placements in this routine. Currently it only supports
  260.      * shop-style placement (all squares except a row nearest the first
  261.      * door get objects).
  262.      */
  263.     register int sx, sy, sh;
  264.     char buf[BUFSZ];
  265.     int rmno = (sroom - rooms) + ROOMOFFSET;
  266.     const struct shclass *shp = &shtypes[shp_indx];
  267.  
  268.     /* first, try to place a shopkeeper in the room */
  269.     if ((sh = shkinit(shp, sroom)) < 0)
  270.     return;
  271.  
  272.     /* make sure no doorways without doors, and no */
  273.     /* trapped doors, in shops.               */
  274.     sx = doors[sroom->fdoor].x;
  275.     sy = doors[sroom->fdoor].y;
  276.  
  277.     if(levl[sx][sy].doormask == D_NODOOR) {
  278.         levl[sx][sy].doormask = D_ISOPEN;
  279.         newsym(sx,sy);
  280.     }
  281.     if(levl[sx][sy].typ == SDOOR) {
  282.         levl[sx][sy].typ = DOOR;
  283.         newsym(sx,sy);
  284.     }
  285.     if(levl[sx][sy].doormask & D_TRAPPED)
  286.         levl[sx][sy].doormask = D_LOCKED;
  287.  
  288.     if(levl[sx][sy].doormask == D_LOCKED) {
  289.         register int m = sx, n = sy;
  290.  
  291.         if(inside_shop(sx+1,sy)) m--;
  292.         else if(inside_shop(sx-1,sy)) m++;
  293.         if(inside_shop(sx,sy+1)) n--;
  294.         else if(inside_shop(sx,sy-1)) n++;
  295.         Sprintf(buf, "Closed for inventory");
  296.         make_engr_at(m, n, buf, 0L, DUST);
  297.     }
  298.  
  299.     for(sx = sroom->lx; sx <= sroom->hx; sx++)
  300.     for(sy = sroom->ly; sy <= sroom->hy; sy++) {
  301.         if(sroom->irregular) {
  302.         if(levl[sx][sy].edge || levl[sx][sy].roomno != rmno ||
  303.            distmin(sx, sy, doors[sh].x, doors[sh].y) <= 1)
  304.             continue;
  305.         } else 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 objects and not the other way around.
  315.      */
  316.  
  317.     level.flags.has_shop = TRUE;
  318. }
  319.  
  320. #endif /* OVLB */
  321. #ifdef OVL0
  322.  
  323. /* does "shop" stock this item type? */
  324. boolean
  325. saleable(shp_indx, obj)
  326. register int shp_indx;
  327. register struct    obj *obj;
  328. {
  329.     register int i;
  330.     register const struct shclass *shp = &shtypes[shp_indx];
  331.  
  332.     if (shp->symb == RANDOM_CLASS) return TRUE;
  333.     else for (i = 0; i < SIZE(shtypes[0].iprobs) && shp->iprobs[i].iprob; i++)
  334.         if (shp->iprobs[i].itype < 0 ?
  335.             shp->iprobs[i].itype == - obj->otyp :
  336.             shp->iprobs[i].itype == obj->oclass) return TRUE;
  337.     /* not found */
  338.     return FALSE;
  339. }
  340.  
  341. /* positive value: class; negative value: specific object type */
  342. int
  343. get_shop_item(type)
  344. int type;
  345. {
  346.     const struct shclass *shp = shtypes+type;
  347.     register int i,j;
  348.  
  349.     /* select an appropriate object type at random */
  350.     for(j = rnd(100), i = 0; (j -= shp->iprobs[i].iprob) > 0; i++)
  351.         continue;
  352.  
  353.     return shp->iprobs[i].itype;
  354. }
  355.  
  356. #endif /* OVL0 */
  357.  
  358. /*shknam.c*/
  359.