1 /* $NetBSD: hack.mkobj.c,v 1.5 2001/03/25 20:44:01 jsm Exp $ */ 2 3 /* 4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. 5 */ 6 7 #include <sys/cdefs.h> 8 #ifndef lint 9 __RCSID("$NetBSD: hack.mkobj.c,v 1.5 2001/03/25 20:44:01 jsm Exp $"); 10 #endif /* not lint */ 11 12 #include "hack.h" 13 #include "extern.h" 14 15 char mkobjstr[] = "))[[!!!!????%%%%/=**))[[!!!!????%%%%/=**(%"; 16 17 struct obj * 18 mkobj_at(let, x, y) 19 int let, x, y; 20 { 21 struct obj *otmp = mkobj(let); 22 otmp->ox = x; 23 otmp->oy = y; 24 otmp->nobj = fobj; 25 fobj = otmp; 26 return (otmp); 27 } 28 29 void 30 mksobj_at(otyp, x, y) 31 int otyp, x, y; 32 { 33 struct obj *otmp = mksobj(otyp); 34 otmp->ox = x; 35 otmp->oy = y; 36 otmp->nobj = fobj; 37 fobj = otmp; 38 } 39 40 struct obj * 41 mkobj(let) 42 int let; 43 { 44 if (!let) 45 let = mkobjstr[rn2(sizeof(mkobjstr) - 1)]; 46 return ( 47 mksobj( 48 letter(let) ? 49 CORPSE + ((let > 'Z') ? (let - 'a' + 'Z' - '@' + 1) : (let - '@')) 50 : probtype(let) 51 ) 52 ); 53 } 54 55 56 struct obj zeroobj; 57 58 struct obj * 59 mksobj(otyp) 60 int otyp; 61 { 62 struct obj *otmp; 63 char let = objects[otyp].oc_olet; 64 65 otmp = newobj(0); 66 *otmp = zeroobj; 67 otmp->age = moves; 68 otmp->o_id = flags.ident++; 69 otmp->quan = 1; 70 otmp->olet = let; 71 otmp->otyp = otyp; 72 otmp->dknown = strchr("/=!?*", let) ? 0 : 1; 73 switch (let) { 74 case WEAPON_SYM: 75 otmp->quan = (otmp->otyp <= ROCK) ? rn1(6, 6) : 1; 76 if (!rn2(11)) 77 otmp->spe = rnd(3); 78 else if (!rn2(10)) { 79 otmp->cursed = 1; 80 otmp->spe = -rnd(3); 81 } 82 break; 83 case FOOD_SYM: 84 if (otmp->otyp >= CORPSE) 85 break; 86 #ifdef NOT_YET_IMPLEMENTED 87 /* if tins are to be identified, need to adapt doname() etc */ 88 if (otmp->otyp == TIN) 89 otmp->spe = rnd(...); 90 #endif /* NOT_YET_IMPLEMENTED */ 91 /* fall into next case */ 92 case GEM_SYM: 93 otmp->quan = rn2(6) ? 1 : 2; 94 case TOOL_SYM: 95 case CHAIN_SYM: 96 case BALL_SYM: 97 case ROCK_SYM: 98 case POTION_SYM: 99 case SCROLL_SYM: 100 case AMULET_SYM: 101 break; 102 case ARMOR_SYM: 103 if (!rn2(8)) 104 otmp->cursed = 1; 105 if (!rn2(10)) 106 otmp->spe = rnd(3); 107 else if (!rn2(9)) { 108 otmp->spe = -rnd(3); 109 otmp->cursed = 1; 110 } 111 break; 112 case WAND_SYM: 113 if (otmp->otyp == WAN_WISHING) 114 otmp->spe = 3; 115 else 116 otmp->spe = rn1(5, 117 (objects[otmp->otyp].bits & NODIR) ? 11 : 4); 118 break; 119 case RING_SYM: 120 if (objects[otmp->otyp].bits & SPEC) { 121 if (!rn2(3)) { 122 otmp->cursed = 1; 123 otmp->spe = -rnd(2); 124 } else 125 otmp->spe = rnd(2); 126 } else if (otmp->otyp == RIN_TELEPORTATION || 127 otmp->otyp == RIN_AGGRAVATE_MONSTER || 128 otmp->otyp == RIN_HUNGER || !rn2(9)) 129 otmp->cursed = 1; 130 break; 131 default: 132 panic("impossible mkobj"); 133 } 134 otmp->owt = weight(otmp); 135 return (otmp); 136 } 137 138 int 139 letter(c) 140 int c; 141 { 142 return (('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z')); 143 } 144 145 int 146 weight(obj) 147 struct obj *obj; 148 { 149 int wt = objects[obj->otyp].oc_weight; 150 return (wt ? wt * obj->quan : (obj->quan + 1) / 2); 151 } 152 153 void 154 mkgold(long num, int x, int y) 155 { 156 struct gold *gold; 157 long amount = (num ? num : 1 + (rnd(dlevel + 2) * rnd(30))); 158 159 if ((gold = g_at(x, y)) != NULL) 160 gold->amount += amount; 161 else { 162 gold = newgold(); 163 gold->ngold = fgold; 164 gold->gx = x; 165 gold->gy = y; 166 gold->amount = amount; 167 fgold = gold; 168 /* do sth with display? */ 169 } 170 } 171