void uswapwepgone(void) { if (uswapwep) { setworn(NULL, W_SWAPWEP); update_inventory(); } }
int doweararm(void) { struct obj *otmp; int delay; int err = 0; long mask = 0; otmp = getobj("[", "wear"); if(!otmp) return(0); if(otmp->owornmask & W_ARMOR) { pline("You are already wearing that!"); return(0); } if(otmp->otyp == HELMET){ if(uarmh) { pline("You are already wearing a helmet."); err++; } else mask = W_ARMH; } else if(otmp->otyp == SHIELD){ if(uarms) pline("You are already wearing a shield."), err++; if(uwep && uwep->otyp == TWO_HANDED_SWORD) pline("You cannot wear a shield and wield a two-handed sword."), err++; if(!err) mask = W_ARMS; } else if(otmp->otyp == PAIR_OF_GLOVES) { if(uarmg) { pline("You are already wearing gloves."); err++; } else if(uwep && uwep->cursed) { pline("You cannot wear gloves over your weapon."); err++; } else mask = W_ARMG; } else { if(uarm) { if(otmp->otyp != ELVEN_CLOAK || uarm2) { pline("You are already wearing some armor."); err++; } } if(!err) mask = W_ARM; } if(otmp == uwep && uwep->cursed) { if(!err++) pline("%s is welded to your hand.", Doname(uwep)); } if(err) return(0); setworn(otmp, mask); if(otmp == uwep) setuwep((struct obj *) 0); delay = -objects[otmp->otyp].oc_delay; if(delay){ nomul(delay); nomovemsg = "You finished your dressing manoeuvre."; } otmp->known = 1; return(1); }
/* Proper usage includes: * 1. Initializing the slot during character generation or a * restore. * 2. Setting the slot due to a player's actions. * 3. If one of the objects in the slot are split off, these * functions can be used to put the remainder back in the slot. * 4. Putting an item that was thrown and returned back into the slot. * 5. Emptying the slot, by passing a null object. NEVER pass * zeroobj! * * If the item is being moved from another slot, it is the caller's * responsibility to handle that. It's also the caller's responsibility * to print the appropriate messages. */ void setuwep(struct obj *obj) { struct obj *olduwep = uwep; if (obj == uwep) return; /* necessary to not set unweapon */ /* This message isn't printed in the caller because it happens * *whenever* Sunsword is unwielded, from whatever cause. */ setworn(obj, W_WEP); if (uwep == obj && artifact_light(olduwep) && olduwep->lamplit) { end_burn(olduwep, FALSE); if (!Blind) pline("%s glowing.", Tobjnam(olduwep, "stop")); } /* Note: Explicitly wielding a pick-axe will not give a "bashing" * message. Wielding one via 'a'pplying it will. * 3.2.2: Wielding arbitrary objects will give bashing message too. */ if (obj) { unweapon = (obj->oclass == WEAPON_CLASS) ? is_launcher(obj) || is_ammo(obj) || is_missile(obj) || (is_pole(obj) && !u.usteed) : !is_weptool(obj); } else unweapon = TRUE; /* for "bare hands" message */ update_inventory(); }
void ringoff(struct obj *obj) { long mask; mask = obj->owornmask & W_RING; setworn(NULL, obj->owornmask); if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask)) impossible("Strange... I didn't know you had that ring."); u.uprops[PROP(obj->otyp)].p_flgs &= ~mask; switch(obj->otyp) { case RIN_FIRE_RESISTANCE: /* Bad luck if the player is in hell... --jgm */ if (!Fire_resistance && dlevel >= 30) { pline("The flames of Hell burn you to a crisp."); killer = "stupidity in hell"; done("burned"); } break; case RIN_LEVITATION: if(!Levitation) { /* no longer floating */ float_down(); } break; case RIN_GAIN_STRENGTH: u.ustr -= obj->spe; u.ustrmax -= obj->spe; if(u.ustr > 118) u.ustr = 118; if(u.ustrmax > 118) u.ustrmax = 118; flags.botl = 1; break; case RIN_INCREASE_DAMAGE: u.udaminc -= obj->spe; break; } }
void uqwepgone(void) { if (uquiver) { setworn(NULL, W_QUIVER); update_inventory(); } }
/* An object you're wearing has been taken off by a monster (theft or seduction). Also used if a worn item gets transformed (stone to flesh). */ void remove_worn_item(struct obj *obj, boolean unchain_ball) { /* whether to unpunish or just unwield */ if (donning(obj)) cancel_don(); if (!obj->owornmask) return; if (obj->owornmask & W_ARMOR) { if (obj == uskin) { impossible("Removing embedded scales?"); skinback(TRUE); /* uarm = uskin; uskin = 0; */ } if (obj == uarm) Armor_off(); else if (obj == uarmc) Cloak_off(); else if (obj == uarmf) Boots_off(); else if (obj == uarmg) Gloves_off(); else if (obj == uarmh) Helmet_off(); else if (obj == uarms) Shield_off(); else if (obj == uarmu) Shirt_off(); /* catchall -- should never happen */ else setworn(NULL, obj->owornmask & W_ARMOR); } else if (obj->owornmask & W_AMUL) { Amulet_off(); } else if (obj->owornmask & W_RING) { Ring_gone(obj); } else if (obj->owornmask & W_TOOL) { Blindf_off(obj); } else if (obj->owornmask & (W_WEP | W_SWAPWEP | W_QUIVER)) { if (obj == uwep) uwepgone(); if (obj == uswapwep) uswapwepgone(); if (obj == uquiver) uqwepgone(); } if (obj->owornmask & (W_BALL | W_CHAIN)) { if (unchain_ball) unpunish(); } else if (obj->owornmask) { /* catchall */ setnotworn(obj); } }
/* These should be used only when the item can't be put back in * the slot by life saving. Proper usage includes: * 1. The item has been eaten, stolen, burned away, or rotted away. * 2. Making an item disappear for a bones pile. */ void uwepgone(void) { if (uwep) { if (artifact_light(uwep) && uwep->lamplit) { end_burn(uwep, FALSE); if (!Blind) pline("%s glowing.", Tobjnam(uwep, "stop")); } setworn(NULL, W_WEP); unweapon = TRUE; update_inventory(); } }
bool armoroff(struct obj *otmp) { int delay = -objects[otmp->otyp].oc_delay; setworn(NULL, otmp->owornmask & W_ARMOR); if(delay) { nomul(delay); switch(otmp->otyp) { case HELMET: nomovemsg = "You finished taking off your helmet."; break; case PAIR_OF_GLOVES: nomovemsg = "You finished taking off your gloves"; break; default: nomovemsg = "You finished taking off your suit."; } } else { off_msg(otmp); } return(1); }
bool dorecover (void) { char savefile [PATH_MAX]; snprintf (ArrayBlock(savefile), HACK_SAVEFILE, getenv("HOME")); int fd = open (savefile, O_RDONLY); if (fd < 0) return false; mread (fd, &_u, sizeof(struct you)); if (_u.maxdlevel < 1 || _u.maxdlevel > MAXLEVEL) { close (fd); you_dtor(); return false; } invent = restobjchn (fd); for (struct obj* o = invent; o; o = o->nobj) if (o->owornmask) setworn (o, o->owornmask); fcobj = restobjchn (fd); fallen_down = restmonchn (fd); mread (fd, &_wflags, sizeof(struct worldflag)); mread (fd, pl_character, sizeof pl_character); restnames (fd); restgenocided (fd); for (unsigned i = 0; i < _u.maxdlevel; ++i) { level_dtor (&_levels[i]); getlev (fd, &_levels[i]); } if (_u.dlevel < 1 || _u.dlevel > _u.maxdlevel) _u.dlevel = _u.maxdlevel; _level = &_levels[_u.dlevel-1]; setsee(); // only to recompute seelx etc. - these weren't saved docrt(); close (fd); unlink (savefile); return true; }
static void newgame(void) { int i; flags.ident = 1; for (i = 0; i < NUMMONS; i++) mvitals[i].mvflags = mons[i].geno & G_NOCORPSE; init_objects(); /* must be before u_init() */ flags.pantheon = -1;/* role_init() will reset this */ role_init(); /* must be before init_dungeons(), u_init(), * and init_artifacts() */ init_dungeons(); /* must be before u_init() to avoid rndmonst() * creating odd monsters for any tins and eggs * in hero's initial inventory */ init_artifacts(); u_init(); /* struct you must have some basic data for mklev to work right */ load_qtlist(); /* load up the quest text info */ level = mklev(&u.uz); u_init_inv_skills();/* level must be valid to create items */ u_on_upstairs(); vision_reset(); /* set up internals for level (after mklev) */ check_special_room(FALSE); iflags.botl = 1; /* Move the monster from under you or else * makedog() will fail when it calls makemon(). * - ucsfcgl!kneller */ if (MON_AT(level, u.ux, u.uy)) mnexto(m_at(level, u.ux, u.uy)); makedog(); doredraw(); if (Role_if(PM_CONVICT)) { setworn(mkobj(level, CHAIN_CLASS, TRUE), W_CHAIN); setworn(mkobj(level, BALL_CLASS, TRUE), W_BALL); uball->spe = 1; /* attach the ball to the hero */ placebc(); } /* help the window port get it's display charset/tiles sorted out */ notify_levelchange(NULL); if (flags.legacy) { flush_screen(); com_pager(Role_if(PM_CONVICT) ? 199 : 1); } /* Stop autoexplore revisiting the entrance stairs (or position). */ level->locations[u.ux][u.uy].mem_stepped = 1; program_state.something_worth_saving++; /* useful data now exists */ historic_event(FALSE, "entered the Dungeons of Doom to retrieve the Amulet of Yendor!"); /* Success! */ welcome(TRUE); maybe_tutorial(); /* Prepare for the first move. */ flags.move = 0; set_wear(); pickup(1); log_command_result(); program_state.game_running = TRUE; youmonst.movement = NORMAL_SPEED; /* give the hero some movement points */ realtime_tasks(); post_init_tasks(); return; }
void setuwep(struct obj *obj) { setworn(obj, W_WEP); }
static void break_armor(void) { struct obj *otmp; if (breakarm(youmonst.data)) { if ((otmp = uarm) != 0) { if (donning(otmp)) cancel_don(); pline("You break out of your armor!"); exercise(A_STR, FALSE); Armor_gone(); useup(otmp); } if ((otmp = uarmc) != 0) { if (otmp->oartifact) { pline("Your %s falls off!", cloak_simple_name(otmp)); Cloak_off(); dropx(otmp); } else { pline("Your %s tears apart!", cloak_simple_name(otmp)); Cloak_off(); useup(otmp); } } if (uarmu) { pline("Your shirt rips to shreds!"); useup(uarmu); } } else if (sliparm(youmonst.data)) { if (((otmp = uarm) != 0) && (racial_exception(&youmonst, otmp) < 1)) { if (donning(otmp)) cancel_don(); pline("Your armor falls around you!"); Armor_gone(); dropx(otmp); } if ((otmp = uarmc) != 0) { if (is_whirly(youmonst.data)) pline("Your %s falls, unsupported!", cloak_simple_name(otmp)); else pline("You shrink out of your %s!", cloak_simple_name(otmp)); Cloak_off(); dropx(otmp); } if ((otmp = uarmu) != 0) { if (is_whirly(youmonst.data)) pline("You seep right through your shirt!"); else pline("You become much too small for your shirt!"); setworn(NULL, otmp->owornmask & W_ARMU); dropx(otmp); } } if (has_horns(youmonst.data)) { if ((otmp = uarmh) != 0) { if (is_flimsy(otmp) && !donning(otmp)) { char hornbuf[BUFSZ], yourbuf[BUFSZ]; /* Future possiblities: This could damage/destroy helmet */ sprintf(hornbuf, "horn%s", plur(num_horns(youmonst.data))); pline("Your %s %s through %s %s.", hornbuf, vtense(hornbuf, "pierce"), shk_your(yourbuf, otmp), xname(otmp)); } else { if (donning(otmp)) cancel_don(); pline("Your helmet falls to the %s!", surface(u.ux, u.uy)); Helmet_off(); dropx(otmp); } } } if (nohands(youmonst.data) || verysmall(youmonst.data)) { if ((otmp = uarmg) != 0) { if (donning(otmp)) cancel_don(); /* Drop weapon along with gloves */ pline("You drop your gloves%s!", uwep ? " and weapon" : ""); drop_weapon(0); Gloves_off(); dropx(otmp); } if ((otmp = uarms) != 0) { pline("You can no longer hold your shield!"); Shield_off(); dropx(otmp); } if ((otmp = uarmh) != 0) { if (donning(otmp)) cancel_don(); pline("Your helmet falls to the %s!", surface(u.ux, u.uy)); Helmet_off(); dropx(otmp); } } if (nohands(youmonst.data) || verysmall(youmonst.data) || slithy(youmonst.data) || youmonst.data->mlet == S_CENTAUR) { if ((otmp = uarmf) != 0) { if (donning(otmp)) cancel_don(); if (is_whirly(youmonst.data)) pline("Your boots fall away!"); else pline("Your boots %s off your feet!", verysmall(youmonst.data) ? "slide" : "are pushed"); Boots_off(); dropx(otmp); } } }
/* * Allocate a new and possibly larger storage space for an obj. */ struct obj * realloc_obj(struct obj *obj, int oextra_size, void *oextra_src, int oname_size, const char *name) { struct obj *otmp; otmp = newobj(oextra_size + oname_size, obj); if (oextra_size) { if (oextra_src) memcpy(otmp->oextra, oextra_src, oextra_size); } else { otmp->oattached = OATTACHED_NOTHING; } otmp->oxlth = oextra_size; otmp->onamelth = oname_size; if (oname_size) { if (name) strcpy(ONAME_MUTABLE(otmp), name); } /* !obj->olev means the obj is currently being restored and no pointer from or to it is valid. Re-equipping, timer linking, etc. will happen elsewhere in that case. */ if (obj->olev) { int i; if (obj->owornmask) { boolean save_twoweap = u.twoweap; /* unwearing the old instance will clear dual-wield mode if this object is either of the two weapons */ setworn(NULL, obj->owornmask); setworn(otmp, otmp->owornmask); u.twoweap = save_twoweap; } /* replace obj with otmp */ replace_object(obj, otmp); /* fix ocontainer pointers */ if (Has_contents(obj)) { struct obj *inside; for (inside = obj->cobj; inside; inside = inside->nobj) inside->ocontainer = otmp; } /* move timers and light sources from obj to otmp */ otmp->timed = 0; /* not timed, yet */ if (obj->timed) obj_move_timers(obj, otmp); otmp->lamplit = 0; /* ditto */ if (obj->lamplit) obj_move_light_source(obj, otmp); /* objects possibly being manipulated by multi-turn occupations which have been interrupted but might be subsequently resumed */ for (i = 0; i <= tos_last_slot; i++) { if (obj == u.utracked[i]) u.utracked[i] = otmp; } /* This is probably paranoia; it would only come up if an item can end up being specific-named as a result of trying to use it. */ for (i = 0; i <= ttos_last_slot; i++) { if (obj == turnstate.tracked[i]) turnstate.tracked[i] = otmp; } } else { /* During restore, floating objects are on the floating objects chain, /but/ may not have OBJ_FREE set. */ otmp->where = obj->where; obj->where = OBJ_FREE; obj->timed = FALSE; obj->lamplit = FALSE; } /* obfree(obj, otmp); now unnecessary: no pointers on bill */ dealloc_obj(obj); /* let us hope nobody else saved a pointer */ return otmp; }
int dowearring(void) { struct obj *otmp; long mask = 0; long oldprop; if (uleft && uright) { pline("There are no more ring-fingers to fill."); return (0); } otmp = getobj("=", "wear"); if (!otmp) return (0); if (otmp->owornmask & W_RING) { pline("You are already wearing that!"); return (0); } if (otmp == uleft || otmp == uright) { pline("You are already wearing that."); return (0); } if (otmp == uwep && uwep->cursed) { pline("%s is welded to your hand.", Doname(uwep)); return (0); } if (uleft) mask = RIGHT_RING; else if (uright) mask = LEFT_RING; else do { char answer; pline("What ring-finger, Right or Left? "); if (strchr(quitchars, (answer = readchar()))) return (0); switch (answer) { case 'l': case 'L': mask = LEFT_RING; break; case 'r': case 'R': mask = RIGHT_RING; break; } } while (!mask); setworn(otmp, mask); if (otmp == uwep) setuwep((struct obj *) 0); oldprop = u.uprops[PROP(otmp->otyp)].p_flgs; u.uprops[PROP(otmp->otyp)].p_flgs |= mask; switch (otmp->otyp) { case RIN_LEVITATION: if (!oldprop) float_up(); break; case RIN_PROTECTION_FROM_SHAPE_CHANGERS: rescham(); break; case RIN_GAIN_STRENGTH: u.ustr += otmp->spe; u.ustrmax += otmp->spe; if (u.ustr > 118) u.ustr = 118; if (u.ustrmax > 118) u.ustrmax = 118; flags.botl = 1; break; case RIN_INCREASE_DAMAGE: u.udaminc += otmp->spe; break; } prinv(otmp); return (1); }
/* return TRUE if mon still alive */ bool hmon(struct monst *mon, struct obj *obj, int thrown) { int tmp; bool hittxt = FALSE; if (!obj) { tmp = rnd(2); /* attack with bare hands */ if (mon->data->mlet == 'c' && !uarmg) { pline("You hit the cockatrice with your bare hands."); pline("You turn to stone ..."); done_in_by(mon); } } else if (obj->olet == WEAPON_SYM || obj->otyp == PICK_AXE) { if (obj == uwep && (obj->otyp > SPEAR || obj->otyp < BOOMERANG)) tmp = rnd(2); else { if (strchr(mlarge, mon->data->mlet)) { tmp = rnd(objects[obj->otyp].wldam); if (obj->otyp == TWO_HANDED_SWORD) tmp += d(2, 6); else if (obj->otyp == FLAIL) tmp += rnd(4); } else tmp = rnd(objects[obj->otyp].wsdam); tmp += obj->spe; if (!thrown && obj == uwep && obj->otyp == BOOMERANG && !rn2(3)) { pline("As you hit %s, the boomerang breaks into splinters.", monnam(mon)); freeinv(obj); setworn(NULL, obj->owornmask); obfree(obj, NULL); tmp++; } } if (mon->data->mlet == 'O' && obj->otyp == TWO_HANDED_SWORD && !strcmp(ONAME(obj), "Orcrist")) tmp += rnd(10); } else switch (obj->otyp) { case HEAVY_IRON_BALL: tmp = rnd(25); break; case EXPENSIVE_CAMERA: pline("You succeed in destroying your camera. Congratulations!"); freeinv(obj); if (obj->owornmask) setworn(NULL, obj->owornmask); obfree(obj, NULL); return (TRUE); case DEAD_COCKATRICE: pline("You hit %s with the cockatrice corpse.", monnam(mon)); if (mon->data->mlet == 'c') { tmp = 1; hittxt = TRUE; break; } pline("%s is turned to stone!", Monnam(mon)); killed(mon); return (FALSE); case CLOVE_OF_GARLIC: /* no effect against demons */ if (strchr(UNDEAD, mon->data->mlet)) mon->mflee = 1; tmp = 1; break; default: /* non-weapons can damage because of their weight */ /* (but not too much) */ tmp = obj->owt / 10; if (tmp < 1) tmp = 1; else tmp = rnd(tmp); if (tmp > 6) tmp = 6; } /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */ tmp += u.udaminc + dbon(); if (u.uswallow) { if ((tmp -= u.uswldtim) <= 0) { pline("Your arms are no longer able to hit."); return (TRUE); } } if (tmp < 1) tmp = 1; mon->mhp -= tmp; if (mon->mhp < 1) { killed(mon); return (FALSE); } if (mon->mtame && (!mon->mflee || mon->mfleetim)) { mon->mflee = 1; /* Rick Richardson */ mon->mfleetim += 10 * rnd(tmp); } if (!hittxt) { if (thrown) { /* this assumes that we cannot throw plural things */ hit(xname(obj) /* or: objects[obj->otyp].oc_name */, mon, exclam(tmp)); } else if (Blind) pline("You hit it."); else pline("You hit %s%s", monnam(mon), exclam(tmp)); } if (u.umconf && !thrown) { if (!Blind) { pline("Your hands stop glowing blue."); if (!mon->mfroz && !mon->msleep) pline("%s appears confused.", Monnam(mon)); } mon->mconf = 1; u.umconf = 0; } return (TRUE); /* mon still alive */ }
int doread() { struct obj *scroll; boolean confused = (Confusion != 0); boolean known = FALSE; scroll = getobj("?", "read"); if(!scroll) return(0); if(!scroll->dknown && Blind) { pline("Being blind, you cannot read the formula on the scroll."); return(0); } if(Blind) pline("As you pronounce the formula on it, the scroll disappears."); else pline("As you read the scroll, it disappears."); if(confused) pline("Being confused, you mispronounce the magic words ... "); switch(scroll->otyp) { #ifdef MAIL case SCR_MAIL: readmail(/* scroll */); break; #endif /* MAIL */ case SCR_ENCHANT_ARMOR: { struct obj *otmp = some_armor(); if(!otmp) { strange_feeling(scroll,"Your skin glows then fades."); return(1); } if(confused) { pline("Your %s glows silver for a moment.", objects[otmp->otyp].oc_name); otmp->rustfree = 1; break; } if(otmp->spe > 3 && rn2(otmp->spe)) { pline("Your %s glows violently green for a while, then evaporates.", objects[otmp->otyp].oc_name); useup(otmp); break; } pline("Your %s glows green for a moment.", objects[otmp->otyp].oc_name); otmp->cursed = 0; otmp->spe++; break; } case SCR_DESTROY_ARMOR: if(confused) { struct obj *otmp = some_armor(); if(!otmp) { strange_feeling(scroll,"Your bones itch."); return(1); } pline("Your %s glows purple for a moment.", objects[otmp->otyp].oc_name); otmp->rustfree = 0; break; } if(uarm) { pline("Your armor turns to dust and falls to the floor!"); useup(uarm); } else if(uarmh) { pline("Your helmet turns to dust and is blown away!"); useup(uarmh); } else if(uarmg) { pline("Your gloves vanish!"); useup(uarmg); selftouch("You"); } else { strange_feeling(scroll,"Your skin itches."); return(1); } break; case SCR_CONFUSE_MONSTER: if(confused) { pline("Your hands begin to glow purple."); Confusion += rnd(100); } else { pline("Your hands begin to glow blue."); u.umconf = 1; } break; case SCR_SCARE_MONSTER: { int ct = 0; struct monst *mtmp; for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) if(cansee(mtmp->mx,mtmp->my)) { if(confused) mtmp->mflee = mtmp->mfroz = mtmp->msleep = 0; else mtmp->mflee = 1; ct++; } if(!ct) { if(confused) pline("You hear sad wailing in the distance."); else pline("You hear maniacal laughter in the distance."); } break; } case SCR_BLANK_PAPER: if(confused) pline("You see strange patterns on this scroll."); else pline("This scroll seems to be blank."); break; case SCR_REMOVE_CURSE: { struct obj *obj; if(confused) pline("You feel like you need some help."); else pline("You feel like someone is helping you."); for(obj = invent; obj ; obj = obj->nobj) if(obj->owornmask) obj->cursed = confused; if(Punished && !confused) { Punished = 0; freeobj(uchain); unpobj(uchain); free(uchain); uball->spe = 0; uball->owornmask &= ~W_BALL; uchain = uball = (struct obj *) 0; } break; } case SCR_CREATE_MONSTER: { int cnt = 1; if(!rn2(73)) cnt += rnd(4); if(confused) cnt += 12; while(cnt--) (void) makemon(confused ? PM_ACID_BLOB : (struct permonst *) 0, u.ux, u.uy); break; } case SCR_ENCHANT_WEAPON: if(uwep && confused) { pline("Your %s glows silver for a moment.", objects[uwep->otyp].oc_name); uwep->rustfree = 1; } else if(!chwepon(scroll, 1)) /* tests for !uwep */ return(1); break; case SCR_DAMAGE_WEAPON: if(uwep && confused) { pline("Your %s glows purple for a moment.", objects[uwep->otyp].oc_name); uwep->rustfree = 0; } else if(!chwepon(scroll, -1)) /* tests for !uwep */ return(1); break; case SCR_TAMING: { int i,j; int bd = confused ? 5 : 1; struct monst *mtmp; for(i = -bd; i <= bd; i++) for(j = -bd; j <= bd; j++) if ((mtmp = m_at(u.ux+i, u.uy+j))) (void) tamedog(mtmp, NULL); break; } case SCR_GENOCIDE: { extern char genocided[], fut_geno[]; char buf[BUFSZ]; struct monst *mtmp, *mtmp2; pline("You have found a scroll of genocide!"); known = TRUE; if(confused) *buf = u.usym; else do { pline("What monster do you want to genocide (Type the letter)? "); getlin(buf); } while(strlen(buf) != 1 || !monstersym(*buf)); if(!strchr(fut_geno, *buf)) charcat(fut_geno, *buf); if(!strchr(genocided, *buf)) charcat(genocided, *buf); else { pline("Such monsters do not exist in this world."); break; } for(mtmp = fmon; mtmp; mtmp = mtmp2){ mtmp2 = mtmp->nmon; if(mtmp->data->mlet == *buf) mondead(mtmp); } pline("Wiped out all %c's.", *buf); if(*buf == u.usym) { killer = "scroll of genocide"; u.uhp = -1; } break; } case SCR_LIGHT: if(!Blind) known = TRUE; litroom(!confused); break; case SCR_TELEPORTATION: if(confused) level_tele(); else { #ifdef QUEST int oux = u.ux, ouy = u.uy; tele(); if(dist(oux, ouy) > 100) known = TRUE; #else /* QUEST */ int uroom = inroom(u.ux, u.uy); tele(); if(uroom != inroom(u.ux, u.uy)) known = TRUE; #endif /* QUEST */ } break; case SCR_GOLD_DETECTION: /* Unfortunately this code has become slightly less elegant, now that gold and traps no longer are of the same type. */ if(confused) { struct trap *ttmp; if(!ftrap) { strange_feeling(scroll, "Your toes stop itching."); return(1); } else { for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) if(ttmp->tx != u.ux || ttmp->ty != u.uy) goto outtrapmap; /* only under me - no separate display required */ pline("Your toes itch!"); break; outtrapmap: cls(); for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) at(ttmp->tx, ttmp->ty, '$'); prme(); pline("You feel very greedy!"); } } else { struct gold *gtmp; if(!fgold) { strange_feeling(scroll, "You feel materially poor."); return(1); } else { known = TRUE; for(gtmp = fgold; gtmp; gtmp = gtmp->ngold) if(gtmp->gx != u.ux || gtmp->gy != u.uy) goto outgoldmap; /* only under me - no separate display required */ pline("You notice some gold between your feet."); break; outgoldmap: cls(); for(gtmp = fgold; gtmp; gtmp = gtmp->ngold) at(gtmp->gx, gtmp->gy, '$'); prme(); pline("You feel very greedy, and sense gold!"); } } /* common sequel */ more(); docrt(); break; case SCR_FOOD_DETECTION: { int ct = 0, ctu = 0; struct obj *obj; char foodsym = confused ? POTION_SYM : FOOD_SYM; for(obj = fobj; obj; obj = obj->nobj) if(obj->olet == FOOD_SYM) { if(obj->ox == u.ux && obj->oy == u.uy) ctu++; else ct++; } if(!ct && !ctu) { strange_feeling(scroll,"Your nose twitches."); return(1); } else if(!ct) { known = TRUE; pline("You smell %s close nearby.", confused ? "something" : "food"); } else { known = TRUE; cls(); for(obj = fobj; obj; obj = obj->nobj) if(obj->olet == foodsym) at(obj->ox, obj->oy, FOOD_SYM); prme(); pline("Your nose tingles and you smell %s!", confused ? "something" : "food"); more(); docrt(); } break; } case SCR_IDENTIFY: /* known = TRUE; */ if(confused) pline("You identify this as an identify scroll."); else pline("This is an identify scroll."); useup(scroll); objects[SCR_IDENTIFY].oc_name_known = 1; if(!confused) while( !ggetobj("identify", identify, rn2(5) ? 1 : rn2(5)) && invent ); return(1); case SCR_MAGIC_MAPPING: { struct rm *lev; int num, zx, zy; known = TRUE; pline("On this scroll %s a map!", confused ? "was" : "is"); for(zy = 0; zy < ROWNO; zy++) for(zx = 0; zx < COLNO; zx++) { if(confused && rn2(7)) continue; lev = &(levl[zx][zy]); if((num = lev->typ) == 0) continue; if(num == SCORR) { lev->typ = CORR; lev->scrsym = CORR_SYM; } else if(num == SDOOR) { lev->typ = DOOR; lev->scrsym = '+'; /* do sth in doors ? */ } else if(lev->seen) continue; #ifndef QUEST if(num != ROOM) #endif /* QUEST */ { lev->seen = lev->new = 1; if(lev->scrsym == ' ' || !lev->scrsym) newsym(zx,zy); else on_scr(zx,zy); } } break; } case SCR_AMNESIA: { int zx, zy; known = TRUE; for(zx = 0; zx < COLNO; zx++) for(zy = 0; zy < ROWNO; zy++) if(!confused || rn2(7)) if(!cansee(zx,zy)) levl[zx][zy].seen = 0; docrt(); pline("Thinking of Maud you forget everything else."); break; } case SCR_FIRE: { int num; struct monst *mtmp; known = TRUE; if(confused) { pline("The scroll catches fire and you burn your hands."); losehp(1, "scroll of fire"); } else { pline("The scroll erupts in a tower of flame!"); if(Fire_resistance) pline("You are uninjured."); else { num = rnd(6); u.uhpmax -= num; losehp(num, "scroll of fire"); } } num = (2*num + 1)/3; for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { if(dist(mtmp->mx,mtmp->my) < 3) { mtmp->mhp -= num; if(strchr("FY", mtmp->data->mlet)) mtmp->mhp -= 3*num; /* this might well kill 'F's */ if(mtmp->mhp < 1) { killed(mtmp); break; /* primitive */ } } } break; } case SCR_PUNISHMENT: known = TRUE; if(confused) { pline("You feel guilty."); break; } pline("You are being punished for your misbehaviour!"); if(Punished){ pline("Your iron ball gets heavier."); uball->owt += 15; break; } Punished = INTRINSIC; setworn(mkobj_at(CHAIN_SYM, u.ux, u.uy), W_CHAIN); setworn(mkobj_at(BALL_SYM, u.ux, u.uy), W_BALL); uball->spe = 1; /* special ball (see save) */ break; default: impossible("What weird language is this written in? (%u)", scroll->otyp); }
static void ini_inv(struct trobj *trop) { struct obj *obj; while (trop->trolet) { obj = mkobj(trop->trolet); obj->known = trop->trknown; /* not obj->dknown = 1; - let him look at it at least once */ obj->cursed = 0; if (obj->olet == WEAPON_SYM) { obj->quan = trop->trquan; trop->trquan = 1; } if (trop->trspe != UNDEF_SPE) obj->spe = trop->trspe; if (trop->trotyp != UNDEF_TYP) obj->otyp = trop->trotyp; else if (obj->otyp == WAN_WISHING) /* gitpyr!robert */ obj->otyp = WAN_DEATH; obj->owt = weight(obj); /* defined after setting otyp+quan */ obj = addinv(obj); if (obj->olet == ARMOR_SYM) { switch (obj->otyp) { case SHIELD: if (!uarms) setworn(obj, W_ARMS); break; case HELMET: if (!uarmh) setworn(obj, W_ARMH); break; case PAIR_OF_GLOVES: if (!uarmg) setworn(obj, W_ARMG); break; case ELVEN_CLOAK: if (!uarm2) setworn(obj, W_ARM); break; default: if (!uarm) setworn(obj, W_ARM); } } if (obj->olet == WEAPON_SYM) if (!uwep) setuwep(obj); #ifndef PYRAMID_BUG if (--trop->trquan) /* make a similar object */ continue; #else if (trop->trquan) { /* check if zero first */ --trop->trquan; if (trop->trquan) continue; /* make a similar object */ } #endif /* PYRAMID_BUG */ trop++; } }
// returns 1 when something was stolen // (or at least, when N should flee now) // avoid stealing the object stealoid int steal(struct monst *mtmp) { struct obj *otmp; int tmp; int named = 0; if (!invent) { if (Blind) pline("Somebody tries to rob you, but finds nothing to steal."); else pline("%s tries to rob you, but she finds nothing to steal!", Monnam(mtmp)); return 1; // let her flee } tmp = 0; for (otmp = invent; otmp; otmp = otmp->nobj) if (otmp != uarm2) tmp += ((otmp->owornmask & (W_ARMOR | W_RING)) ? 5 : 1); tmp = rn2(tmp); for (otmp = invent; otmp; otmp = otmp->nobj) if (otmp != uarm2) if ((tmp -= ((otmp->owornmask & (W_ARMOR | W_RING)) ? 5 : 1)) < 0) break; if (!otmp) { impossible("Steal fails!"); return 0; } if (otmp->o_id == stealoid) return 0; if ((otmp->owornmask & (W_ARMOR | W_RING))) { switch (otmp->olet) { case RING_SYM: ringoff(otmp); break; case ARMOR_SYM: if (multi < 0 || otmp == uarms) { setworn((struct obj *) 0, otmp->owornmask & W_ARMOR); break; } { int curssv = otmp->cursed; otmp->cursed = 0; stop_occupation(); pline("%s seduces you and %s off your %s.", Amonnam(mtmp, Blind ? "gentle" : "beautiful"), otmp->cursed ? "helps you to take" : "you start taking", (otmp == uarmg) ? "gloves" : (otmp == uarmh) ? "helmet" : "armor"); named++; (void) armoroff(otmp); otmp->cursed = curssv; if (multi < 0) { // multi = 0; // nomovemsg = 0; // afternmv = 0; stealoid = otmp->o_id; stealmid = mtmp->m_id; afternmv = stealarm; return 0; } break; } default: impossible("Tried to steal a strange worn thing."); } } else if (otmp == uwep) setuwep((struct obj *) 0); if (otmp->olet == CHAIN_SYM) { impossible("How come you are carrying that chain?"); } if (Punished && otmp == uball) { Punished = 0; freeobj(uchain); free((char *) uchain); uchain = (struct obj *) 0; uball->spe = 0; uball = (struct obj *) 0; // superfluous } freeinv(otmp); pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp)); mpickobj(mtmp, otmp); return multi < 0 ? 0 : 1; }
int dorecover(int fd) { int nfd; int tmp; /* not a ! */ unsigned mid; /* idem */ struct obj *otmp; restoring = TRUE; getlev(fd, 0, 0); invent = restobjchn(fd); for (otmp = invent; otmp; otmp = otmp->nobj) if (otmp->owornmask) setworn(otmp, otmp->owornmask); fcobj = restobjchn(fd); fallen_down = restmonchn(fd); mread(fd, &tmp, sizeof tmp); if (tmp != (int) getuid()) { /* strange ... */ (void) close(fd); (void) unlink(SAVEF); puts("Saved game was not yours."); restoring = FALSE; return (0); } mread(fd, &flags, sizeof(struct flag)); mread(fd, &dlevel, sizeof dlevel); mread(fd, &maxdlevel, sizeof maxdlevel); mread(fd, &moves, sizeof moves); mread(fd, &u, sizeof(struct you)); if (u.ustuck) mread(fd, &mid, sizeof mid); mread(fd, pl_character, sizeof pl_character); mread(fd, genocided, sizeof genocided); mread(fd, fut_geno, sizeof fut_geno); restnames(fd); while (1) { if (read(fd, &tmp, sizeof tmp) != sizeof tmp) break; getlev(fd, 0, tmp); glo(tmp); if ((nfd = creat(lock, FMASK)) < 0) panic("Cannot open temp file %s!\n", lock); savelev(nfd, tmp); (void) close(nfd); } (void) lseek(fd, (off_t) 0, SEEK_SET); getlev(fd, 0, 0); (void) close(fd); (void) unlink(SAVEF); if (Punished) { for (otmp = fobj; otmp; otmp = otmp->nobj) if (otmp->olet == CHAIN_SYM) goto chainfnd; panic("Cannot find the iron chain?"); chainfnd: uchain = otmp; if (!uball) { for (otmp = fobj; otmp; otmp = otmp->nobj) if (otmp->olet == BALL_SYM && otmp->spe) goto ballfnd; panic("Cannot find the iron ball?"); ballfnd: uball = otmp; } } if (u.ustuck) { struct monst *mtmp; for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) if (mtmp->m_id == mid) goto monfnd; panic("Cannot find the monster ustuck."); monfnd: u.ustuck = mtmp; } #ifndef QUEST setsee(); /* only to recompute seelx etc. - these * weren't saved */ #endif /* QUEST */ docrt(); restoring = FALSE; return (1); }
/* * Allocate a new and possibly larger storage space for an obj. */ struct obj *realloc_obj(struct obj *obj, int oextra_size, void *oextra_src, int oname_size, const char *name) { struct obj *otmp; otmp = newobj(oextra_size + oname_size); *otmp = *obj; /* the cobj pointer is copied to otmp */ if (oextra_size) { if (oextra_src) memcpy(otmp->oextra, oextra_src, oextra_size); } else { otmp->oattached = OATTACHED_NOTHING; } otmp->oxlth = oextra_size; otmp->onamelth = oname_size; if (oname_size) { if (name) strcpy(ONAME(otmp), name); } /* !obj->olev means the obj is currently being restored and no pointer * from or to it is valid. Re-equipping, timer linking, etc. will happen * elsewhere in that case. */ if (obj->olev) { if (obj->owornmask) { boolean save_twoweap = u.twoweap; /* unwearing the old instance will clear dual-wield mode if this object is either of the two weapons */ setworn(NULL, obj->owornmask); setworn(otmp, otmp->owornmask); u.twoweap = save_twoweap; } /* replace obj with otmp */ replace_object(obj, otmp); /* fix ocontainer pointers */ if (Has_contents(obj)) { struct obj *inside; for (inside = obj->cobj; inside; inside = inside->nobj) inside->ocontainer = otmp; } /* move timers and light sources from obj to otmp */ otmp->timed = 0; /* not timed, yet */ if (obj->timed) obj_move_timers(obj, otmp); otmp->lamplit = 0; /* ditto */ if (obj->lamplit) obj_move_light_source(obj, otmp); /* objects possibly being manipulated by multi-turn occupations which have been interrupted but might be subsequently resumed */ if (obj->oclass == FOOD_CLASS) food_substitution(obj, otmp); /* eat food or open tin */ else if (obj->oclass == SPBOOK_CLASS) book_substitution(obj, otmp); /* read spellbook */ } else { /* make sure dealloc_obj doesn't explode */ obj->where = OBJ_FREE; obj->timed = FALSE; obj->lamplit = FALSE; } /* obfree(obj, otmp); now unnecessary: no pointers on bill */ dealloc_obj(obj); /* let us hope nobody else saved a pointer */ return otmp; }
static void break_armor (void) { struct obj *otmp; if (breakarm(youmonst.data)) { if ((otmp = uarm) != 0) { if (donning(otmp)) cancel_don(); You("break out of your armor!"); exercise(A_STR, false); (void) Armor_gone(); useup(otmp); } if ((otmp = uarmc) != 0) { if(otmp->oartifact) { Your("%s falls off!", cloak_simple_name(otmp)); (void) Cloak_off(); dropx(otmp); } else { Your("%s tears apart!", cloak_simple_name(otmp)); (void) Cloak_off(); useup(otmp); } } if (uarmu) { Your("shirt rips to shreds!"); useup(uarmu); } } else if (sliparm(youmonst.data)) { if (((otmp = uarm) != 0) && (racial_exception(&youmonst, otmp) < 1)) { if (donning(otmp)) cancel_don(); Your("armor falls around you!"); (void) Armor_gone(); dropx(otmp); } if ((otmp = uarmc) != 0) { if (is_whirly(youmonst.data)) Your("%s falls, unsupported!", cloak_simple_name(otmp)); else You("shrink out of your %s!", cloak_simple_name(otmp)); (void) Cloak_off(); dropx(otmp); } if ((otmp = uarmu) != 0) { if (is_whirly(youmonst.data)) You("seep right through your shirt!"); else You("become much too small for your shirt!"); setworn((struct obj *)0, otmp->owornmask & W_ARMU); dropx(otmp); } } if (has_horns(youmonst.data)) { if ((otmp = uarmh) != 0) { if (is_flimsy(otmp) && !donning(otmp)) { /* Future possiblities: This could damage/destroy helmet */ message_object(MSG_YOUR_HORNS_PIERCE_O, otmp); } else { if (donning(otmp)) cancel_don(); Your("helmet falls to the %s!", surface(u.ux, u.uy)); (void) Helmet_off(); dropx(otmp); } } } if (nohands(youmonst.data) || verysmall(youmonst.data)) { if ((otmp = uarmg) != 0) { if (donning(otmp)) cancel_don(); /* Drop weapon along with gloves */ You("drop your gloves%s!", uwep ? " and weapon" : ""); drop_weapon(0); (void) Gloves_off(); dropx(otmp); } if ((otmp = uarms) != 0) { You("can no longer hold your shield!"); (void) Shield_off(); dropx(otmp); } if ((otmp = uarmh) != 0) { if (donning(otmp)) cancel_don(); Your("helmet falls to the %s!", surface(u.ux, u.uy)); (void) Helmet_off(); dropx(otmp); } } if (nohands(youmonst.data) || verysmall(youmonst.data) || slithy(youmonst.data) || youmonst.data->mlet == S_CENTAUR) { if ((otmp = uarmf) != 0) { if (donning(otmp)) cancel_don(); if (is_whirly(youmonst.data)) Your("boots fall away!"); else Your("boots %s off your feet!", verysmall(youmonst.data) ? "slide" : "are pushed"); (void) Boots_off(); dropx(otmp); } } }
void setuqwep(struct obj *obj) { setworn(obj, W_QUIVER); update_inventory(); }
void setuswapwep(struct obj *obj) { setworn(obj, W_SWAPWEP); update_inventory(); }