hack.mkobj.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* $NetBSD: hack.mkobj.c,v 1.6 2003/04/02 18:36:38 jsm Exp $ */
  2. /*
  3. * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
  4. * Amsterdam
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. *
  11. * - Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. *
  14. * - Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * - Neither the name of the Stichting Centrum voor Wiskunde en
  19. * Informatica, nor the names of its contributors may be used to endorse or
  20. * promote products derived from this software without specific prior
  21. * written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  25. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  26. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  27. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. /*
  36. * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
  37. * All rights reserved.
  38. *
  39. * Redistribution and use in source and binary forms, with or without
  40. * modification, are permitted provided that the following conditions
  41. * are met:
  42. * 1. Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * 2. Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in the
  46. * documentation and/or other materials provided with the distribution.
  47. * 3. The name of the author may not be used to endorse or promote products
  48. * derived from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  51. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  52. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  53. * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  54. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  55. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  56. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  57. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  58. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  59. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  60. */
  61. #include <sys/cdefs.h>
  62. #ifndef lint
  63. __RCSID("$NetBSD: hack.mkobj.c,v 1.6 2003/04/02 18:36:38 jsm Exp $");
  64. #endif /* not lint */
  65. #include "hack.h"
  66. #include "extern.h"
  67. char mkobjstr[] = "))[[!!!!????%%%%/=**))[[!!!!????%%%%/=**(%";
  68. struct obj *
  69. mkobj_at(let, x, y)
  70. int let, x, y;
  71. {
  72. struct obj *otmp = mkobj(let);
  73. otmp->ox = x;
  74. otmp->oy = y;
  75. otmp->nobj = fobj;
  76. fobj = otmp;
  77. return (otmp);
  78. }
  79. void
  80. mksobj_at(otyp, x, y)
  81. int otyp, x, y;
  82. {
  83. struct obj *otmp = mksobj(otyp);
  84. otmp->ox = x;
  85. otmp->oy = y;
  86. otmp->nobj = fobj;
  87. fobj = otmp;
  88. }
  89. struct obj *
  90. mkobj(let)
  91. int let;
  92. {
  93. if (!let)
  94. let = mkobjstr[rn2(sizeof(mkobjstr) - 1)];
  95. return (
  96. mksobj(
  97. letter(let) ?
  98. CORPSE + ((let > 'Z') ? (let - 'a' + 'Z' - '@' + 1) : (let - '@'))
  99. : probtype(let)
  100. )
  101. );
  102. }
  103. struct obj zeroobj;
  104. struct obj *
  105. mksobj(otyp)
  106. int otyp;
  107. {
  108. struct obj *otmp;
  109. char let = objects[otyp].oc_olet;
  110. otmp = newobj(0);
  111. *otmp = zeroobj;
  112. otmp->age = moves;
  113. otmp->o_id = flags.ident++;
  114. otmp->quan = 1;
  115. otmp->olet = let;
  116. otmp->otyp = otyp;
  117. otmp->dknown = strchr("/=!?*", let) ? 0 : 1;
  118. switch (let) {
  119. case WEAPON_SYM:
  120. otmp->quan = (otmp->otyp <= ROCK) ? rn1(6, 6) : 1;
  121. if (!rn2(11))
  122. otmp->spe = rnd(3);
  123. else if (!rn2(10)) {
  124. otmp->cursed = 1;
  125. otmp->spe = -rnd(3);
  126. }
  127. break;
  128. case FOOD_SYM:
  129. if (otmp->otyp >= CORPSE)
  130. break;
  131. #ifdef NOT_YET_IMPLEMENTED
  132. /* if tins are to be identified, need to adapt doname() etc */
  133. if (otmp->otyp == TIN)
  134. otmp->spe = rnd(...);
  135. #endif /* NOT_YET_IMPLEMENTED */
  136. /* fall into next case */
  137. case GEM_SYM:
  138. otmp->quan = rn2(6) ? 1 : 2;
  139. case TOOL_SYM:
  140. case CHAIN_SYM:
  141. case BALL_SYM:
  142. case ROCK_SYM:
  143. case POTION_SYM:
  144. case SCROLL_SYM:
  145. case AMULET_SYM:
  146. break;
  147. case ARMOR_SYM:
  148. if (!rn2(8))
  149. otmp->cursed = 1;
  150. if (!rn2(10))
  151. otmp->spe = rnd(3);
  152. else if (!rn2(9)) {
  153. otmp->spe = -rnd(3);
  154. otmp->cursed = 1;
  155. }
  156. break;
  157. case WAND_SYM:
  158. if (otmp->otyp == WAN_WISHING)
  159. otmp->spe = 3;
  160. else
  161. otmp->spe = rn1(5,
  162. (objects[otmp->otyp].bits & NODIR) ? 11 : 4);
  163. break;
  164. case RING_SYM:
  165. if (objects[otmp->otyp].bits & SPEC) {
  166. if (!rn2(3)) {
  167. otmp->cursed = 1;
  168. otmp->spe = -rnd(2);
  169. } else
  170. otmp->spe = rnd(2);
  171. } else if (otmp->otyp == RIN_TELEPORTATION ||
  172. otmp->otyp == RIN_AGGRAVATE_MONSTER ||
  173. otmp->otyp == RIN_HUNGER || !rn2(9))
  174. otmp->cursed = 1;
  175. break;
  176. default:
  177. panic("impossible mkobj");
  178. }
  179. otmp->owt = weight(otmp);
  180. return (otmp);
  181. }
  182. int
  183. letter(c)
  184. int c;
  185. {
  186. return (('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
  187. }
  188. int
  189. weight(obj)
  190. struct obj *obj;
  191. {
  192. int wt = objects[obj->otyp].oc_weight;
  193. return (wt ? wt * obj->quan : (obj->quan + 1) / 2);
  194. }
  195. void
  196. mkgold(long num, int x, int y)
  197. {
  198. struct gold *gold;
  199. long amount = (num ? num : 1 + (rnd(dlevel + 2) * rnd(30)));
  200. if ((gold = g_at(x, y)) != NULL)
  201. gold->amount += amount;
  202. else {
  203. gold = newgold();
  204. gold->ngold = fgold;
  205. gold->gx = x;
  206. gold->gy = y;
  207. gold->amount = amount;
  208. fgold = gold;
  209. /* do sth with display? */
  210. }
  211. }