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.4 2006/08/21 19:45:32 pavalos Exp $ */ 5 6 #include "hack.h" 7 8 char mkobjstr[] = "))[[!!!!????%%%%/=**))[[!!!!????%%%%/=**(%"; 9 10 struct obj * 11 mkobj_at(int let, int x, int y) 12 { 13 struct obj *otmp = mkobj(let); 14 otmp->ox = x; 15 otmp->oy = y; 16 otmp->nobj = fobj; 17 fobj = otmp; 18 return(otmp); 19 } 20 21 void 22 mksobj_at(int otyp, int x, int y) 23 { 24 struct obj *otmp = mksobj(otyp); 25 otmp->ox = x; 26 otmp->oy = y; 27 otmp->nobj = fobj; 28 fobj = otmp; 29 } 30 31 struct obj * 32 mkobj(int let) 33 { 34 if(!let) 35 let = mkobjstr[rn2(sizeof(mkobjstr) - 1)]; 36 return( 37 mksobj( 38 letter(let) ? 39 CORPSE + ((let > 'Z') ? (let-'a'+'Z'-'@'+1) : (let-'@')) 40 : probtype(let) 41 ) 42 ); 43 } 44 45 46 struct obj zeroobj; 47 48 struct obj * 49 mksobj(int otyp) 50 { 51 struct obj *otmp; 52 char let = objects[otyp].oc_olet; 53 54 otmp = newobj(0); 55 *otmp = zeroobj; 56 otmp->age = moves; 57 otmp->o_id = flags.ident++; 58 otmp->quan = 1; 59 otmp->olet = let; 60 otmp->otyp = otyp; 61 otmp->dknown = index("/=!?*", let) ? 0 : 1; 62 switch(let) { 63 case WEAPON_SYM: 64 otmp->quan = (otmp->otyp <= ROCK) ? rn1(6,6) : 1; 65 if(!rn2(11)) otmp->spe = rnd(3); 66 else if(!rn2(10)) { 67 otmp->cursed = 1; 68 otmp->spe = -rnd(3); 69 } 70 break; 71 case FOOD_SYM: 72 if(otmp->otyp >= CORPSE) break; 73 #ifdef NOT_YET_IMPLEMENTED 74 /* if tins are to be identified, need to adapt doname() etc */ 75 if(otmp->otyp == TIN) 76 otmp->spe = rnd(...); 77 #endif /* NOT_YET_IMPLEMENTED */ 78 /* fall into next case */ 79 case GEM_SYM: 80 otmp->quan = rn2(6) ? 1 : 2; 81 case TOOL_SYM: 82 case CHAIN_SYM: 83 case BALL_SYM: 84 case ROCK_SYM: 85 case POTION_SYM: 86 case SCROLL_SYM: 87 case AMULET_SYM: 88 break; 89 case ARMOR_SYM: 90 if(!rn2(8)) otmp->cursed = 1; 91 if(!rn2(10)) otmp->spe = rnd(3); 92 else if(!rn2(9)) { 93 otmp->spe = -rnd(3); 94 otmp->cursed = 1; 95 } 96 break; 97 case WAND_SYM: 98 if(otmp->otyp == WAN_WISHING) otmp->spe = 3; else 99 otmp->spe = rn1(5, 100 (objects[otmp->otyp].bits & NODIR) ? 11 : 4); 101 break; 102 case RING_SYM: 103 if(objects[otmp->otyp].bits & SPEC) { 104 if(!rn2(3)) { 105 otmp->cursed = 1; 106 otmp->spe = -rnd(2); 107 } else otmp->spe = rnd(2); 108 } else if(otmp->otyp == RIN_TELEPORTATION || 109 otmp->otyp == RIN_AGGRAVATE_MONSTER || 110 otmp->otyp == RIN_HUNGER || !rn2(9)) 111 otmp->cursed = 1; 112 break; 113 default: 114 panic("impossible mkobj"); 115 } 116 otmp->owt = weight(otmp); 117 return(otmp); 118 } 119 120 bool 121 letter(char c) 122 { 123 return(('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z')); 124 } 125 126 int 127 weight(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 void 134 mkgold(long num, int x, int y) 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