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