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

  1. /*    SCCS Id: @(#)mkobj.c    3.1    93/05/01    */
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6. #include "artifact.h"
  7. #include "prop.h"
  8.  
  9. STATIC_DCL void FDECL(mkbox_cnts,(struct obj *));
  10.  
  11. struct icp {
  12.     int  iprob; /* probability of an item type */
  13.     char ilet;    /* item class */
  14. };
  15.  
  16. #ifdef OVL1
  17.  
  18. const struct icp mkobjprobs[] = {
  19. {10, WEAPON_CLASS},
  20. {10, ARMOR_CLASS},
  21. {20, FOOD_CLASS},
  22. { 8, TOOL_CLASS},
  23. { 8, GEM_CLASS},
  24. {16, POTION_CLASS},
  25. {16, SCROLL_CLASS},
  26. { 4, SPBOOK_CLASS},
  27. { 4, WAND_CLASS},
  28. { 3, RING_CLASS},
  29. { 1, AMULET_CLASS}
  30. };
  31.  
  32. const struct icp boxiprobs[] = {
  33. {18, GEM_CLASS},
  34. {15, FOOD_CLASS},
  35. {18, POTION_CLASS},
  36. {18, SCROLL_CLASS},
  37. {12, SPBOOK_CLASS},
  38. { 7, GOLD_CLASS},
  39. { 6, WAND_CLASS},
  40. { 5, RING_CLASS},
  41. { 1, AMULET_CLASS}
  42. };
  43.  
  44. #ifdef REINCARNATION
  45. const struct icp rogueprobs[] = {
  46. {12, WEAPON_CLASS},
  47. {12, ARMOR_CLASS},
  48. {22, FOOD_CLASS},
  49. {22, POTION_CLASS},
  50. {22, SCROLL_CLASS},
  51. { 5, WAND_CLASS},
  52. { 5, RING_CLASS}
  53. };
  54. #endif
  55.  
  56. const struct icp hellprobs[] = {
  57. {20, WEAPON_CLASS},
  58. {20, ARMOR_CLASS},
  59. {16, FOOD_CLASS},
  60. {12, TOOL_CLASS},
  61. {10, GEM_CLASS},
  62. { 1, POTION_CLASS},
  63. { 1, SCROLL_CLASS},
  64. { 8, WAND_CLASS},
  65. { 8, RING_CLASS},
  66. { 4, AMULET_CLASS}
  67. };
  68.  
  69. struct obj *
  70. mkobj_at(let,x,y, artif)
  71. char let;
  72. int x,y;
  73. boolean artif;
  74. {
  75.     register struct obj *otmp;
  76.  
  77.     otmp = mkobj(let,artif);
  78.     otmp->nobj = fobj;
  79.     fobj = otmp;
  80.     place_object(otmp, x, y);
  81.     return(otmp);
  82. }
  83.  
  84. struct obj *
  85. mksobj_at(otyp,x,y,init)
  86. int otyp,x,y;
  87. boolean init;
  88. {
  89.     register struct obj *otmp;
  90.  
  91.     otmp = mksobj(otyp,init,TRUE);
  92.     otmp->nobj = fobj;
  93.     fobj = otmp;
  94.     place_object(otmp, x, y);
  95.     return(otmp);
  96. }
  97.  
  98. struct obj *
  99. mkobj(let, artif)
  100. char let;
  101. boolean artif;
  102. {
  103.     register int tprob, i, prob = rnd(1000);
  104.  
  105.     if(let == RANDOM_CLASS) {
  106.         const struct icp *iprobs =
  107. #ifdef REINCARNATION
  108.                     (Is_rogue_level(&u.uz)) ?
  109.                     (const struct icp *)rogueprobs :
  110. #endif
  111.                     Inhell ? (const struct icp *)hellprobs :
  112.                     (const struct icp *)mkobjprobs;
  113.  
  114.         for(tprob = rnd(100);
  115.             (tprob -= iprobs->iprob) > 0;
  116.             iprobs++);
  117.         let = iprobs->ilet;
  118.     }
  119.  
  120.     i = bases[letindex(let)];
  121.     while((prob -= objects[i].oc_prob) > 0) i++;
  122.  
  123.     if(objects[i].oc_class != let || !OBJ_NAME(objects[i]))
  124.         panic("probtype error, let=%c i=%d", let, i);
  125.  
  126.     return(mksobj(i, TRUE, artif));
  127. }
  128.  
  129. STATIC_OVL void
  130. mkbox_cnts(box)
  131. /* Note: does not check to see if it overloaded the box capacity; usually
  132.  * possible only with corpses in ice boxes.
  133.  */
  134. struct obj *box;
  135. {
  136.     register int n;
  137.     register struct obj *otmp, *gold = 0;
  138.  
  139.     box->cobj = (struct obj *) 0;
  140.  
  141.     switch(box->otyp) {
  142.         case ICE_BOX:        n = 20; break;
  143.         case CHEST:        n = 5; break;
  144.         case LARGE_BOX:        n = 3; break;
  145.         case SACK:
  146.         case OILSKIN_SACK:
  147.         case BAG_OF_HOLDING:    n = 1; break;
  148.         default:        n = 0; break;
  149.     }
  150.  
  151.     for (n = rn2(n+1); n > 0; n--) {
  152.         if (box->otyp == ICE_BOX) {
  153.         if (!(otmp = mksobj(CORPSE, TRUE, TRUE))) continue;
  154.         /* Note: setting age to 0 is correct.  Age has a different
  155.          * from usual meaning for objects stored in ice boxes. -KAA
  156.          */
  157.         otmp->age = 0L;
  158.         } else {
  159.         register int tprob;
  160.         const struct icp *iprobs = boxiprobs;
  161.  
  162.         for (tprob = rnd(100); (tprob -= iprobs->iprob) > 0; iprobs++)
  163.             ;
  164.         if (!(otmp = mkobj(iprobs->ilet, TRUE))) continue;
  165.  
  166.         /* handle a couple of special cases */
  167.         if (otmp->otyp == GOLD_PIECE) {
  168.             /* 2.5 x level's usual amount; weight adjusted below */
  169.             otmp->quan = (long)(rnd(level_difficulty()+2) * rnd(75));
  170.             if (gold) {            /* gold already in this box */
  171.             gold->quan += otmp->quan;    /* merge */
  172.             dealloc_obj(otmp);    /* note: not yet in any chain */
  173.             continue;
  174.             } else {
  175.             gold = otmp;        /* remember this object */
  176.             }
  177.         } else while (otmp->otyp == ROCK) {
  178.             otmp->otyp = rnd_class(DILITHIUM_CRYSTAL, LOADSTONE);
  179.             if (otmp->quan > 2L) otmp->quan = 1L;
  180.             otmp->owt = weight(otmp);
  181.         }
  182.         if (box->otyp == BAG_OF_HOLDING) {
  183.             if (Is_mbag(otmp)) {
  184.             otmp->otyp = SACK;
  185.             otmp->spe = 0;
  186.             otmp->owt = weight(otmp);
  187.             } else while (otmp->otyp == WAN_CANCELLATION)
  188.                 otmp->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING);
  189.         }
  190.         }
  191.         otmp->nobj = box->cobj;
  192.         box->cobj = otmp;
  193.     }
  194.     if (gold) gold->owt = weight(gold);    /* quantity was diddled */
  195.     return;
  196. }
  197.  
  198. int
  199. rndmonnum()    /* select a random, common monster type */
  200. {
  201.     register struct permonst *ptr;
  202.     register int    i;
  203.  
  204.     /* Plan A: get a level-appropriate common monster */
  205.     ptr = rndmonst();
  206.     if (ptr) return(monsndx(ptr));
  207.  
  208.     /* Plan B: get any common monster */
  209.     do {
  210.         ptr = &mons[(i = rn2(NUMMONS))];
  211.     } while((ptr->geno & G_NOGEN) || (!Inhell && (ptr->geno & G_HELL)));
  212.  
  213.     return(i);
  214. }
  215.  
  216. #endif /* OVL1 */
  217. #ifdef OVLB
  218. const char dknowns[] = { WAND_CLASS, RING_CLASS, POTION_CLASS, SCROLL_CLASS,
  219.              GEM_CLASS, SPBOOK_CLASS, WEAPON_CLASS, 0};
  220.  
  221. /*ARGSUSED*/
  222. struct obj *
  223. mksobj(otyp, init, artif)
  224. int otyp;
  225. boolean init;
  226. boolean artif;
  227. {
  228.     int tryct;
  229.     struct obj *otmp;
  230.     char let = objects[otyp].oc_class;
  231.  
  232.     otmp = newobj(0);
  233.     *otmp = zeroobj;
  234.     otmp->age = monstermoves;
  235.     otmp->o_id = flags.ident++;
  236.     otmp->quan = 1L;
  237.     otmp->oclass = let;
  238.     otmp->otyp = otyp;
  239.     otmp->dknown = index(dknowns, let) ? 0 : 1;
  240.     if (!objects[otmp->otyp].oc_uses_known)
  241.         otmp->known = 1;
  242.     if (init) switch (let) {
  243.     case WEAPON_CLASS:
  244.         otmp->quan = (otmp->otyp <= SHURIKEN) ? (long) rn1(6,6) : 1L;
  245.         if(!rn2(11)) {
  246.             otmp->spe = rne(3);
  247.             otmp->blessed = rn2(2);
  248.         } else if(!rn2(10)) {
  249.             curse(otmp);
  250.             otmp->spe = -rne(3);
  251.         } else    blessorcurse(otmp, 10);
  252.  
  253.         if (artif && !rn2(20))
  254.             otmp = mk_artifact(otmp, (aligntyp)A_NONE);
  255.         break;
  256.     case FOOD_CLASS:
  257.         otmp->oeaten = 0;
  258.         switch(otmp->otyp) {
  259.         case CORPSE:
  260.             /* overridden by mkcorpstat() */
  261.             do otmp->corpsenm = rndmonnum();
  262.             while (mons[otmp->corpsenm].geno & G_NOCORPSE);
  263.             break;
  264.         case EGG:
  265.             if(!rn2(3)) {        /* "live" eggs */
  266.             register struct permonst *ptr;
  267.             for(tryct = 0;
  268.                 (!(ptr = rndmonst()) ||
  269.                 (!lays_eggs(ptr) && ptr != &mons[PM_KILLER_BEE])) &&
  270.                 tryct < 100;
  271.                 tryct++);
  272.             if(tryct < 100)    otmp->corpsenm = monsndx(ptr);
  273.             else        otmp->corpsenm = -1; /* empty */
  274.             } else        otmp->corpsenm = -1; /* empty */
  275.             break;
  276.         case TIN:
  277.             if(!rn2(6)) {
  278.             otmp->spe = 1;        /* spinach */
  279.             otmp->corpsenm = -1;
  280.             } else do {
  281.             otmp->corpsenm = rndmonnum();
  282.             } while (mons[otmp->corpsenm].geno & G_NOCORPSE);
  283.             blessorcurse(otmp, 10);
  284.             break;
  285. #ifdef TUTTI_FRUTTI
  286.         case SLIME_MOLD:
  287.             otmp->spe = current_fruit;
  288.             break;
  289. #endif
  290.         }
  291.         if (otmp->otyp == CORPSE) break;
  292.         /* fall into next case */
  293.  
  294.     case GEM_CLASS:
  295.         if (otmp->otyp == LOADSTONE) curse(otmp);
  296.         else if (otmp->otyp == ROCK) otmp->quan = (long) rn1(6,6);
  297.         else if (otmp->otyp != LUCKSTONE && !rn2(6)) otmp->quan = 2L;
  298.         else otmp->quan = 1L;
  299.         break;
  300.     case TOOL_CLASS:
  301.         switch(otmp->otyp) {
  302.         case TALLOW_CANDLE:
  303.         case WAX_CANDLE:    otmp->spe = 1;
  304.                     otmp->age = 20L * /* 400 or 200 */
  305.                           (long)objects[otmp->otyp].oc_cost;
  306.                     otmp->lamplit = 0;
  307.                     otmp->quan = 1L +
  308.                           (long)(rn2(2) ? rn2(7) : 0);
  309.                     blessorcurse(otmp, 5);
  310.                     break;
  311.         case BRASS_LANTERN:
  312.         case OIL_LAMP:        otmp->spe = 1;
  313.                     otmp->age = (long) rn1(500,1000);
  314.                     otmp->lamplit = 0;
  315.                     blessorcurse(otmp, 5);
  316.                     break;
  317.         case MAGIC_LAMP:    otmp->spe = 1;
  318.                     otmp->lamplit = 0;
  319.                     blessorcurse(otmp, 2);
  320.                     break;
  321.         case CHEST:
  322.         case LARGE_BOX:        otmp->olocked = !!(rn2(5));
  323.                     otmp->otrapped = !(rn2(10));
  324.         case ICE_BOX:
  325.         case SACK:
  326.         case OILSKIN_SACK:
  327.         case BAG_OF_HOLDING:    mkbox_cnts(otmp);
  328.                     break;
  329.         case MAGIC_MARKER:    otmp->spe = rn1(70,30);
  330.                     break;
  331.         case CAN_OF_GREASE:    otmp->spe = rnd(25);
  332.                     blessorcurse(otmp, 10);
  333.                     break;
  334.         case CRYSTAL_BALL:    otmp->spe = rnd(5);
  335.                     blessorcurse(otmp, 2);
  336.                     break;
  337.         case HORN_OF_PLENTY:
  338.         case BAG_OF_TRICKS:    otmp->spe = rnd(20);
  339.                     break;
  340.         case FIGURINE:    {    int tryct2 = 0;
  341.                     do
  342.                         otmp->corpsenm = rndmonnum();
  343.                     while(is_human(&mons[otmp->corpsenm])
  344.                         && tryct2++ < 30);
  345.                     blessorcurse(otmp, 4);
  346.                     break;
  347.                 }
  348.         case BELL_OF_OPENING:   otmp->spe = 3;
  349.                     break;
  350.         case MAGIC_FLUTE:
  351.         case MAGIC_HARP:
  352.         case FROST_HORN:
  353.         case FIRE_HORN:
  354.         case DRUM_OF_EARTHQUAKE:
  355.                     otmp->spe = rn1(5,4);
  356.                     break;
  357.         }
  358.         break;
  359.     case AMULET_CLASS:
  360.         if(rn2(10) && (otmp->otyp == AMULET_OF_STRANGULATION ||
  361.            otmp->otyp == AMULET_OF_CHANGE ||
  362.            otmp->otyp == AMULET_OF_RESTFUL_SLEEP)) {
  363.             curse(otmp);
  364.         } else    blessorcurse(otmp, 10);
  365.     case VENOM_CLASS:
  366.     case CHAIN_CLASS:
  367.     case BALL_CLASS:
  368.         break;
  369.     case POTION_CLASS:
  370.     case SCROLL_CLASS:
  371. #ifdef MAIL
  372.         if (otmp->otyp != SCR_MAIL)
  373. #endif
  374.             blessorcurse(otmp, 4);
  375.         break;
  376.     case SPBOOK_CLASS:
  377.         blessorcurse(otmp, 17);
  378.         break;
  379.     case ARMOR_CLASS:
  380.         if(rn2(10) && (otmp->otyp == FUMBLE_BOOTS ||
  381.            otmp->otyp == LEVITATION_BOOTS ||
  382.            otmp->otyp == HELM_OF_OPPOSITE_ALIGNMENT ||
  383.            otmp->otyp == GAUNTLETS_OF_FUMBLING ||
  384.            !rn2(11))) {
  385.             curse(otmp);
  386.             otmp->spe = -rne(3);
  387.         } else if(!rn2(10)) {
  388.             otmp->blessed = rn2(2);
  389.             otmp->spe = rne(3);
  390.         } else    blessorcurse(otmp, 10);
  391.         break;
  392.     case WAND_CLASS:
  393.         if(otmp->otyp == WAN_WISHING) otmp->spe = rnd(3); else
  394.         otmp->spe = rn1(5,
  395.             (objects[otmp->otyp].oc_dir == NODIR) ? 11 : 4);
  396.         blessorcurse(otmp, 17);
  397.         otmp->recharged = 0; /* used to control recharging */
  398.         break;
  399.     case RING_CLASS:
  400.         if(objects[otmp->otyp].oc_charged) {
  401.             blessorcurse(otmp, 3);
  402.             if(rn2(10)) {
  403.             if(rn2(10) && bcsign(otmp))
  404.                 otmp->spe = bcsign(otmp) * rne(3);
  405.             else otmp->spe = rn2(2) ? rne(3) : -rne(3);
  406.             }
  407.             /* make useless +0 rings much less common */
  408.             if (otmp->spe == 0) otmp->spe = rn2(4) - rn2(3);
  409.             /* negative rings are usually cursed */
  410.             if (otmp->spe < 0 && rn2(5)) curse(otmp);
  411.         } else if(rn2(10) && (otmp->otyp == RIN_TELEPORTATION ||
  412. #ifdef POLYSELF
  413.               otmp->otyp == RIN_POLYMORPH ||
  414. #endif
  415.               otmp->otyp == RIN_AGGRAVATE_MONSTER ||
  416.               otmp->otyp == RIN_HUNGER || !rn2(9))) {
  417.             curse(otmp);
  418.         }
  419.         break;
  420.     case ROCK_CLASS:
  421.         switch (otmp->otyp) {
  422.             case STATUE:
  423.             if (rn2(level_difficulty()/2 + 10) > 10) {
  424.                 struct obj *book;
  425.                 book = mkobj(SPBOOK_CLASS,FALSE);
  426.                 otmp->cobj = book;
  427.             }
  428.             /* overridden by mkcorpstat() */
  429.             otmp->corpsenm = rndmonnum();
  430.         }
  431.         break;
  432.     case GOLD_CLASS:
  433.         break;    /* do nothing */
  434.     default:
  435.         impossible("impossible mkobj %d, sym '%c'.", otmp->otyp, objects[otmp->otyp].oc_class);
  436.         return (struct obj *)0;
  437.     }
  438.     /* unique objects may have an associated artifact entry */
  439.     if (objects[otyp].oc_unique && !otmp->oartifact)
  440.         otmp = mk_artifact(otmp, (aligntyp)A_NONE);
  441.     otmp->owt = weight(otmp);
  442.     return(otmp);
  443. }
  444.  
  445. void
  446. bless(otmp)
  447. register struct obj *otmp;
  448. {
  449.     otmp->cursed = 0;
  450.     otmp->blessed = 1;
  451.     if (otmp->otyp == LUCKSTONE
  452.         || (otmp->oartifact && spec_ability(otmp, SPFX_LUCK))) {
  453.         int luckbon = stone_luck(TRUE);
  454.         if(!luckbon && !carrying(LUCKSTONE)) u.moreluck = 0;
  455.         else if (luckbon >= 0) u.moreluck = LUCKADD;
  456.         else u.moreluck = -LUCKADD;
  457.     } else if (otmp->otyp == BAG_OF_HOLDING)
  458.         otmp->owt = weight(otmp);
  459.     return;
  460. }
  461.  
  462. void
  463. unbless(otmp)
  464. register struct obj *otmp;
  465. {
  466.     otmp->blessed = 0;
  467.     if (otmp->otyp == LUCKSTONE
  468.         || (otmp->oartifact && spec_ability(otmp, SPFX_LUCK))) {
  469.         int luckbon = stone_luck(TRUE);
  470.         if (!luckbon && !carrying(LUCKSTONE)) u.moreluck = 0;
  471.         else if (luckbon >= 0) u.moreluck = LUCKADD;
  472.         else u.moreluck = -LUCKADD;
  473.     } else if (otmp->otyp == BAG_OF_HOLDING)
  474.         otmp->owt = weight(otmp);
  475. }
  476.  
  477. void
  478. curse(otmp)
  479. register struct obj *otmp;
  480. {
  481.     otmp->blessed = 0;
  482.     otmp->cursed = 1;
  483.     if (otmp->otyp == LUCKSTONE
  484.         || (otmp->oartifact && spec_ability(otmp, SPFX_LUCK))) {
  485.         int luckbon = stone_luck(TRUE);
  486.         if (!luckbon && !carrying(LUCKSTONE)) u.moreluck = 0;
  487.         else if (luckbon >= 0) u.moreluck = LUCKADD;
  488.         else u.moreluck = -LUCKADD;
  489.     } else if (otmp->otyp == BAG_OF_HOLDING)
  490.         otmp->owt = weight(otmp);
  491.     return;
  492. }
  493.  
  494. void
  495. uncurse(otmp)
  496. register struct obj *otmp;
  497. {
  498.     otmp->cursed = 0;
  499.     if (otmp->otyp == LUCKSTONE
  500.         || (otmp->oartifact && spec_ability(otmp, SPFX_LUCK))) {
  501.         int luckbon = stone_luck(TRUE);
  502.         if (!luckbon && !carrying(LUCKSTONE)) u.moreluck = 0;
  503.         else if (luckbon >= 0) u.moreluck = LUCKADD;
  504.         else u.moreluck = -LUCKADD;
  505.     } else if (otmp->otyp == BAG_OF_HOLDING)
  506.         otmp->owt = weight(otmp);
  507. }
  508.  
  509. #endif /* OVLB */
  510. #ifdef OVL1
  511. void
  512. blessorcurse(otmp, chance)
  513. register struct obj *otmp;
  514. register int chance;
  515. {
  516.     if(otmp->blessed || otmp->cursed) return;
  517.  
  518.     if(!rn2(chance))
  519.         if(!rn2(2)) {
  520.         curse(otmp);
  521.         } else {
  522.         bless(otmp);
  523.         }
  524.     return;
  525. }
  526.  
  527. #endif /* OVL1 */
  528. #ifdef OVLB
  529.  
  530. int
  531. bcsign(otmp)
  532. register struct obj *otmp;
  533. {
  534.     return(!!otmp->blessed - !!otmp->cursed);
  535. }
  536.  
  537. #endif /* OVLB */
  538. #ifdef OVL0
  539.  
  540. /*
  541.  *  Calculate the weight of the given object.  This will recursively follow
  542.  *  and calculate the weight of any containers.
  543.  *
  544.  *  Note:  It is possible to end up with an incorrect weight if some part
  545.  *       of the code messes with a contained object and doesn't update the
  546.  *       container's weight.
  547.  */
  548. int
  549. weight(obj)
  550. register struct obj *obj;
  551. {
  552.     int wt = objects[obj->otyp].oc_weight;
  553.  
  554.     if (Is_container(obj) || obj->otyp == STATUE) {
  555.         struct obj *contents;
  556.         register int cwt = 0;
  557.  
  558.         if (obj->otyp == STATUE && obj->corpsenm > -1)
  559.             wt = (int)obj->quan *
  560.              ((int)mons[obj->corpsenm].cwt * 3 / 2);
  561.  
  562.         for(contents=obj->cobj; contents; contents=contents->nobj)
  563.             cwt += weight(contents);
  564.         /*
  565.          *  The weight of bags of holding is calculated as the weight
  566.          *  of the bag plus the weight of the bag's contents modified
  567.          *  as follows:
  568.          *
  569.          *    Bag status    Weight of contents
  570.          *    ----------    ------------------
  571.          *    cursed            2x
  572.          *    blessed            x/4 + 1
  573.          *    otherwise        x/2 + 1
  574.          *
  575.          *  The macro DELTA_CWT in pickup.c also implements these
  576.          *  weight equations.
  577.          *
  578.          *  Note:  The above checks are performed in the given order.
  579.          *       this means that if an object is both blessed and
  580.          *       cursed (not supposed to happen), it will be treated
  581.          *       as cursed.
  582.          */
  583.         if (obj->otyp == BAG_OF_HOLDING)
  584.             cwt = obj->cursed ? (cwt * 2) :
  585.                     (1 + (cwt / (obj->blessed ? 4 : 2)));
  586.  
  587.         return wt + cwt;
  588.     }
  589.     if (obj->otyp == CORPSE && obj->corpsenm > -1)
  590.         return (int)obj->quan * mons[obj->corpsenm].cwt;
  591.     else if (obj->otyp == GOLD_PIECE)
  592.         return (int)((obj->quan + 50L) / 100L);
  593.     else if (obj->otyp == HEAVY_IRON_BALL && obj->owt != 0)
  594.         return((int)(obj->owt));    /* kludge for "very" heavy iron ball */
  595.     return(wt ? wt*(int)obj->quan : ((int)obj->quan + 1)>>1);
  596. }
  597.  
  598. #endif /* OVL0 */
  599. #ifdef OVLB
  600.  
  601. void
  602. mkgold(amount, x, y)
  603. long amount;
  604. int x, y;
  605. {
  606.     register struct obj *gold = g_at(x,y);
  607.  
  608.     if (amount <= 0L) amount = (long)(1 + rnd(level_difficulty()+2) * rnd(30));
  609.     if (gold) {
  610.     gold->quan += amount;
  611.     } else {
  612.     gold = mksobj_at(GOLD_PIECE,x,y,TRUE);
  613.     gold->quan = amount;
  614.     }
  615.     gold->owt = weight(gold);
  616. }
  617.  
  618. #endif /* OVLB */
  619. #ifdef OVL1
  620. struct obj *
  621. mkcorpstat(objtype, ptr, x, y, init)
  622. int objtype;    /* CORPSE or STATUE */
  623. register struct permonst *ptr;
  624. int x, y;
  625. boolean init;
  626. {
  627.     register struct obj *otmp;
  628.  
  629.     if(objtype != CORPSE && objtype != STATUE)
  630.         impossible("making corpstat type %d", objtype);
  631.     otmp = mksobj_at(objtype, x, y, init);
  632.     if(otmp)  {
  633.         if(ptr)    otmp->corpsenm = monsndx(ptr);
  634.         else    otmp->corpsenm = rndmonnum();
  635.         otmp->owt = weight(otmp);
  636.     }
  637.     return(otmp);
  638. }
  639.  
  640. #endif /* OVL1 */
  641. #ifdef OVLB
  642. struct obj *
  643. mk_tt_object(objtype, x, y)
  644. int objtype; /* CORPSE or STATUE */
  645. register int x, y;
  646. {
  647.     register struct obj *otmp;
  648.  
  649.     /* player statues never contain books */
  650.     if ((otmp = mksobj_at(objtype,x,y,FALSE)) != 0)
  651.         otmp = tt_oname(otmp);
  652.     return(otmp);
  653. }
  654.  
  655. /* make a new corpse or statue, uninitialized if a statue (i.e. no books) */
  656. struct obj *
  657. mk_named_object(objtype, ptr, x, y, nm, lth)
  658. int objtype; /* CORPSE or STATUE */
  659. register struct permonst *ptr;
  660. int x, y;
  661. char * nm;
  662. register int lth;
  663. {
  664.     struct obj *otmp;
  665.  
  666.     otmp = mkcorpstat(objtype,ptr,x,y,(objtype != STATUE));
  667.     if (lth > 0) {
  668.         /* Note: oname() is safe since otmp is first in both chains */
  669.         otmp = oname(otmp, nm, FALSE);
  670.         fobj = otmp;
  671.         level.objects[x][y] = otmp;
  672.     }
  673.     return(otmp);
  674. }
  675.  
  676. boolean
  677. is_flammable(otmp)
  678. register struct obj *otmp;
  679. {
  680.     int otyp = otmp->otyp;
  681.  
  682.     if (objects[otyp].oc_oprop == FIRE_RES) return FALSE;
  683.  
  684.     return((boolean)(objects[otyp].oc_material <= WOOD &&
  685.             objects[otyp].oc_material != LIQUID));
  686. }
  687.  
  688. #endif /* OVLB */
  689. #ifdef OVL1
  690.  
  691. /*
  692.  * These routines maintain the single-linked lists headed in level.objects[][]
  693.  * and threaded through the nexthere fields in the object-instance structure.
  694.  */
  695.  
  696. void
  697. place_object(otmp, x, y)
  698. /* put an object on top of the pile at the given location */
  699. register struct obj *otmp;
  700. int x, y;
  701. {
  702.     register struct obj *otmp2 = level.objects[x][y];
  703.  
  704.     if (otmp->otyp == BOULDER) block_point(x,y);    /* vision */
  705.  
  706.     if (otmp2 && (otmp2->otyp == BOULDER)) {
  707.     otmp->nexthere = otmp2->nexthere;
  708.     otmp2->nexthere = otmp;
  709.     } else {
  710.     otmp->nexthere = otmp2;
  711.     level.objects[x][y] = otmp;
  712.     }
  713.  
  714.     /* set the new object's location */
  715.     otmp->ox = x;
  716.     otmp->oy = y;
  717. }
  718.  
  719. #endif /* OVL1 */
  720. #ifdef OVLB
  721. void
  722. remove_object(otmp)
  723. register struct obj *otmp;
  724. {
  725.     register struct obj *odel;
  726.  
  727.     if (otmp->otyp == BOULDER) unblock_point(otmp->ox,otmp->oy); /* vision */
  728.  
  729.     if (otmp == level.objects[otmp->ox][otmp->oy])
  730.     level.objects[otmp->ox][otmp->oy] = otmp->nexthere;
  731.     else
  732.     for (odel = level.objects[otmp->ox][otmp->oy];
  733.                             odel; odel = odel->nexthere)
  734.         if (odel->nexthere == otmp) {
  735.         odel->nexthere = otmp->nexthere;
  736.         break;
  737.         }
  738. }
  739.  
  740. void
  741. move_object(otmp, x, y)
  742. register struct obj *otmp;
  743. int x, y;
  744. {
  745.     remove_object(otmp);
  746.     place_object(otmp, x, y);
  747. }
  748.  
  749. #endif /* OVLB */
  750.  
  751. /*mkobj.c*/
  752.