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